Example #1
0
        public virtual void TestImageCompressLevel()
        {
            byte[] b = ImageDataFactory.Create(sourceFolder + "berlin2013.jpg").GetData();
            ByteArrayOutputStream image = new ByteArrayOutputStream();

            image.AssignBytes(b, b.Length);
            MemoryStream         byteArrayStream1 = new ByteArrayOutputStream();
            DeflaterOutputStream zip = new DeflaterOutputStream(byteArrayStream1, 9);

            image.WriteTo(zip);
            MemoryStream         byteArrayStream2 = new ByteArrayOutputStream();
            DeflaterOutputStream zip2             = new DeflaterOutputStream(byteArrayStream2, -1);

            image.WriteTo(zip2);
            NUnit.Framework.Assert.IsTrue(byteArrayStream1.Length == byteArrayStream2.Length);
            zip.Dispose();
            zip2.Dispose();
        }
Example #2
0
		public override void Write(int b)
		{
			if (b == '\n')
			{
				// synchronize on "this" first to avoid potential deadlock
				lock (this)
				{
					lock (LogOut)
					{
						// construct prefix for log messages:
						Buffer.Length = 0;
						Buffer.Append((DateTime.Now).ToString()); // date/time stamp...
						Buffer.Append(':');
						Buffer.Append(Name); // ...log name...
						Buffer.Append(':');
						Buffer.Append(Thread.CurrentThread.Name);
						Buffer.Append(':'); // ...and thread name

						try
						{
							// write prefix through to underlying byte stream
							LogWriter.Write(Buffer.ToString());
							LogWriter.Flush();

							// finally, write the already converted bytes of
							// the log message
							BufOut.WriteTo(LogOut);
							LogOut.Write(b);
							LogOut.Flush();
						}
						catch (IOException)
						{
							SetError();
						}
						finally
						{
							BufOut.Reset();
						}
					}
				}
			}
			else
			{
				base.Write(b);
			}
		}
        public override Field[] CreateIndexableFields(IShape shape)
        {
            int bufSize = Math.Max(128, (int)(this.indexLastBufSize * 1.5)); //50% headroom over last
            ByteArrayOutputStream byteStream = new ByteArrayOutputStream(bufSize);
            BytesRef bytesRef = new BytesRef();                              //receiver of byteStream's bytes

            try
            {
                m_ctx.BinaryCodec.WriteShape(new BinaryWriter(byteStream), shape);

                //this is a hack to avoid redundant byte array copying by byteStream.toByteArray()
                byteStream.WriteTo(new OutputStreamAnonymousHelper(bytesRef));
            }
            catch (IOException e)
            {
                throw new Exception(e.ToString(), e);
            }
            this.indexLastBufSize = bytesRef.Length;//cache heuristic
            return(new Field[] { new BinaryDocValuesField(FieldName, bytesRef) });
        }
Example #4
0
        private Stream GetStandardChoiceForm(string sourcePath, string tfn)
        {
            using (var stream = new MemoryStream())
            {
                var baos   = new ByteArrayOutputStream();
                var pdfDoc = new PdfDocument(new PdfReader(sourcePath), new PdfWriter(stream));

                //var doc = new Document(pdfDoc);
                var form = PdfAcroForm.GetAcroForm(pdfDoc, false);

                var fields = form.GetFormFields();
                fields["2-TFN-fill"]?.SetValue(tfn ?? "undefined");

                form.FlattenFields();

                pdfDoc.Close();
                baos.WriteTo(stream);

                return(stream);
            }
        }