Пример #1
0
 public GzipSink(Sink sink)
 {
     if (sink == null)
     {
         throw new ArgumentException("sink == null");
     }
     this.deflater     = new Deflater(Deflater.DEFAULT_COMPRESSION, true /* No wrap */);
     this.sink         = EasyIO.Buffer(sink);
     this.deflaterSink = new DeflaterSink(this.sink, deflater);
     WriteHeader();
 }
Пример #2
0
 /**
  * This package-private constructor shares a buffer with its trusted caller.
  * In general we can't share a BufferedSource because the deflater holds input
  * bytes until they are inflated.
  */
 DeflaterSink(BufferedSink sink, Deflater deflater)
 {
     if (sink == null)
     {
         throw new ArgumentException("source == null");
     }
     if (deflater == null)
     {
         throw new ArgumentException("inflater == null");
     }
     this.sink     = sink;
     this.deflater = deflater;
 }
Пример #3
0
        public void readWriteFile()
        {
            string       tempFile = Path.GetTempFileName();
            BufferedSink sink     = EasyIO.Buffer(EasyIO.Sink(tempFile));

            sink.WriteUtf8("Hello, easy.io file!");
            sink.Dispose();
            Assert.True(File.Exists(tempFile));
            var allText = File.ReadAllText(tempFile);

            Assert.AreEqual(20, allText.Length);
            BufferedSource source = EasyIO.Buffer(EasyIO.Source(tempFile));

            Assert.AreEqual("Hello, easy.io file!", source.ReadUtf8());
            source.Dispose();
        }
Пример #4
0
        public void setOutputSecurityCodec(byte[] key, bool compress)
        {
            if (Trace.isInfoEnabled())
            {
                Trace.info(manager + " " + this + " setOutputSecurityCodec key = " + (key == null ? "" : Helper.toHexString(key)) + " compress = " + compress);
            }
            Codec codec = new BufferedSink(new NetTaskCodecSink(this));

            if (null != key)
            {
                codec = new Encrypt(codec, key);
            }
            if (compress)
            {
                codec = new RFC2118Encode(codec);
            }
            output.Dispose();
            output = codec;
        }
Пример #5
0
        public void appendFile()
        {
            string       tempFile = Path.GetTempFileName();
            BufferedSink sink     = EasyIO.Buffer(EasyIO.Sink(tempFile, FileMode.Append));

            sink.WriteUtf8("Hello, ");
            sink.Dispose();
            Assert.True(File.Exists(tempFile));
            Assert.AreEqual(7, File.ReadAllText(tempFile).Length);

            sink = EasyIO.Buffer(EasyIO.Sink(tempFile, FileMode.Append));
            sink.WriteUtf8("easy.io file!");
            sink.Dispose();
            Assert.AreEqual(20, File.ReadAllText(tempFile).Length);

            BufferedSource source = EasyIO.Buffer(EasyIO.Source(tempFile));

            Assert.AreEqual("Hello, easy.io file!", source.ReadUtf8());
            source.Dispose();
        }