Java 类java.io.FilterOutputStream 实例源码

项目:GitHub    文件:ScalaZipCodeWriter.java   
@Override
public OutputStream openBinary(final JPackage pkg, String fileName) throws IOException {
    final ByteArrayOutputStream javaSourceStream = new ByteArrayOutputStream();

    final String scalaFileName = fileName.replaceAll("\\.java$", ".scala");

    return new FilterOutputStream(javaSourceStream) {
        @Override
        public void close() throws IOException {
            super.close();

            final String javaSource = new String(javaSourceStream.toByteArray(), "utf-8");
            final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false));

            OutputStream parentStream = ScalaZipCodeWriter.super.openBinary(pkg, scalaFileName);
            parentStream.write(scalaSource.getBytes("utf-8"));
        }
    };
}
项目:GitHub    文件:ScalaSingleStreamCodeWriter.java   
@Override
public OutputStream openBinary(final JPackage pkg, String fileName) throws IOException {
    final ByteArrayOutputStream javaSourceStream = new ByteArrayOutputStream();

    final String scalaFileName = fileName.replaceAll("\\.java$", ".scala");

    return new FilterOutputStream(javaSourceStream) {
        @Override
        public void close() throws IOException {
            super.close();

            final String javaSource = new String(javaSourceStream.toByteArray(), "utf-8");
            final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false));

            OutputStream parentStream = ScalaSingleStreamCodeWriter.super.openBinary(pkg, scalaFileName);
            parentStream.write(scalaSource.getBytes("utf-8"));
        }
    };
}
项目:GitHub    文件:ScalaFileCodeWriter.java   
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    final ByteArrayOutputStream javaSourceStream = new ByteArrayOutputStream();

    final String javaFileName = getFile(pkg, fileName).getAbsolutePath();
    final String scalaFileName = javaFileName.replaceAll("\\.java$", ".scala");

    return new FilterOutputStream(javaSourceStream) {
        public void close() throws IOException {
            super.close();

            final String javaSource = new String(javaSourceStream.toByteArray(), encoding);
            final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false));

            FileUtils.writeStringToFile(new File(scalaFileName), scalaSource, encoding);
        }
    };
}
项目:incubator-netbeans    文件:PropertiesStorage.java   
private OutputStream outputStream() throws IOException {
    FileObject fo = toPropertiesFile(true);
    final FileLock lock = fo.lock();
    OutputStream os = null;
    try {
        os = fo.getOutputStream(lock);
    } finally {
        if(os == null && lock != null) {
            // release lock if getOutputStream failed
            lock.releaseLock();
        }
    }
    return new FilterOutputStream(os) {
        public @Override void close() throws IOException {
            super.close();
            lock.releaseLock();
        }
    };
}
项目:incubator-netbeans    文件:LocalFileSystem.java   
private OutputStream getOutputStreamForMac42624(final OutputStream originalStream, final String name) {
    final File f = getFile(name);
    final long lModified = f.lastModified();
    OutputStream retVal = new FilterOutputStream(originalStream) {

        @Override
        public void close() throws IOException {
            super.close();

            if ((f.length() == 0) && (f.lastModified() == lModified)) {
                f.setLastModified(System.currentTimeMillis());
            }
        }
    };

    return retVal;
}
项目:incubator-netbeans    文件:FileObject75826Test.java   
TestFileSystem(LocalFileSystem lfs, String testName) throws Exception {
    super();
    if ("testOutputStreamFiresIOException".equals(testName)) {
        this.info = new LocalFileSystem.Impl(this) {
            public OutputStream outputStream(String name) throws java.io.IOException {
                throw new IOException();
            }
        };
    } else if ("testCloseStreamFiresIOException".equals(testName)) {
        this.info = new LocalFileSystem.Impl(this) {
            public OutputStream outputStream(String name) throws java.io.IOException {
                return new FilterOutputStream(super.outputStream(name)) {
                    public void close() throws IOException {
                        throw new IOException();
                    }
                };
            }
        };
    }
    setRootDirectory(lfs.getRootDirectory());
}
项目:fluentxml4j    文件:XmlResult.java   
public OutputStream getOutputStream()
{
    return new FilterOutputStream(new ByteArrayOutputStream())
    {
        @Override
        public void flush() throws IOException
        {
            super.flush();
            publishData();
        }

        @Override
        public void close() throws IOException
        {
            super.close();
            publishData();
        }

        private void publishData()
        {
            ByteArrayOutputStream bytesOut = (ByteArrayOutputStream) out;
            XmlResult.this.dataHolder = new BytesDataHolder(bytesOut.toByteArray());
        }
    };
}
项目:LoRaWAN-Smart-Parking    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:LoRaWAN-Smart-Parking    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:openjdk-jdk10    文件:ToolBox.java   
@Override
public OutputStream openOutputStream() {
    return new FilterOutputStream(new ByteArrayOutputStream()) {
        @Override
        public void close() throws IOException {
            out.close();
            byte[] bytes = ((ByteArrayOutputStream) out).toByteArray();
            save(location, name, new Content() {
                @Override
                public byte[] getBytes() {
                    return bytes;
                }
                @Override
                public String getString() {
                    return new String(bytes);
                }

            });
        }
    };
}
项目:openjdk-jdk10    文件:SingleStreamCodeWriter.java   
@Override
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    final String name = pkg != null && pkg.name().length() > 0
            ? pkg.name() + '.' + fileName : fileName;

    out.println(
        "-----------------------------------" + name +
        "-----------------------------------");

    return new FilterOutputStream(out) {
        @Override
        public void close() {
            // don't let this stream close
        }
    };
}
项目:openjdk9    文件:ToolBox.java   
@Override
public OutputStream openOutputStream() {
    return new FilterOutputStream(new ByteArrayOutputStream()) {
        @Override
        public void close() throws IOException {
            out.close();
            byte[] bytes = ((ByteArrayOutputStream) out).toByteArray();
            save(location, name, new Content() {
                @Override
                public byte[] getBytes() {
                    return bytes;
                }
                @Override
                public String getString() {
                    return new String(bytes);
                }

            });
        }
    };
}
项目:SumZeroTrading    文件:ApiConnection.java   
@Override public synchronized void eConnect(Socket socket, int clientId) throws IOException {
    super.eConnect(socket, clientId);

    // replace the output stream with one that logs all data to m_outLogger
    if (isConnected()) {
        try {
            Field realOsField = FilterOutputStream.class.getDeclaredField( "out");
            realOsField.setAccessible( true);
            OutputStream realOs = (OutputStream)realOsField.get( m_dos);
            realOsField.set( m_dos, new MyOS( realOs) );
        }
        catch( Exception e) {
            e.printStackTrace();
        }
    }
}
项目:trading-indexFutureAndOptions    文件:ApiConnection.java   
@Override public synchronized void eConnect(Socket socket, int clientId) throws IOException {
    super.eConnect(socket, clientId);

    // replace the output stream with one that logs all data to m_outLogger
    if (isConnected()) {
        try {
            Field realOsField = FilterOutputStream.class.getDeclaredField( "out");
            realOsField.setAccessible( true);
            OutputStream realOs = (OutputStream)realOsField.get( m_dos);
            realOsField.set( m_dos, new MyOS( realOs) );
        }
        catch( Exception e) {
            e.printStackTrace();
        }
    }
}
项目:smart-mirror-app    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:cordova-plugin-background-mode    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:multirotorstuff-vtx-calc    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:L.TileLayer.Cordova    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:cordova-android-tv    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:Cordova-Locale-Plugin    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:pubnub-rpi-smart-parking    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:IoTgo_Android_App    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:j2objc    文件:OldFilterOutputStreamTest.java   
public void test_flush() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(550);
    os = new FilterOutputStream(sos);
    os.write(fileString.getBytes(), 0, 500);
    os.flush();
    assertEquals("Test 1: Bytes not written after flush;",
            500, sos.size());

    sos.setThrowsException(true);
    try {
        os.flush();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
        // Expected.
    }
    sos.setThrowsException(false);
}
项目:j2objc    文件:OldFilterOutputStreamTest.java   
public void test_write$B() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(testLength);
    os = new FilterOutputStream(sos);
    os.write(fileString.getBytes());

    bis = new ByteArrayInputStream(sos.toByteArray());
    assertTrue("Test 1: Bytes have not been written.",
            bis.available() == testLength);
    byte[] wbytes = new byte[testLength];
    bis.read(wbytes, 0, testLength);
    assertTrue("Test 2: Incorrect bytes written or read.",
            fileString.equals(new String(wbytes)));

    try {
        // Support_OutputStream throws an IOException if the internal
        // buffer is full, which it should be now.
        os.write(42);
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
        // Expected.
    }
}
项目:j2objc    文件:OldFilterOutputStreamTest.java   
public void test_write$BII() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(testLength);
    os = new FilterOutputStream(sos);
    os.write(fileString.getBytes(), 10, testLength - 10);

    bis = new ByteArrayInputStream(sos.toByteArray());
    assertTrue("Test 1: Bytes have not been written.",
            bis.available() == testLength - 10);
    byte[] wbytes = new byte[testLength - 10];
    bis.read(wbytes);
    assertTrue("Test 2: Incorrect bytes written or read.",
            fileString.substring(10).equals(new String(wbytes)));

    try {
        // Support_OutputStream throws an IOException if the internal
        // buffer is full, which it should be eventually.
        os.write(fileString.getBytes());
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
        // Expected.
    }
}
项目:j2objc    文件:OldFilterOutputStreamTest.java   
public void test_writeI() throws IOException {
    Support_OutputStream sos = new Support_OutputStream(1);
    os = new FilterOutputStream(sos);
    os.write(42);

    bis = new ByteArrayInputStream(sos.toByteArray());
    assertTrue("Test 1: Byte has not been written.",
            bis.available() == 1);
    assertEquals("Test 2: Incorrect byte written or read;",
            42, bis.read());

    try {
        // Support_OutputStream throws an IOException if the internal
        // buffer is full, which it should be now.
        os.write(42);
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
        // Expected.
    }
}
项目:CanDoVS2015    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:krakn    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:krakn    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:krakn    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:krakn    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:krakn    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:posjs2    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:knowledgestore    文件:Dictionary.java   
private OutputStream writeWithBackup() throws IOException {

        // 1. delete filename.new if it exists
        delete(".new");

        // 2. if filename exists, rename it to filename.backup (deleting old backup)
        if (lastModified("") != null) {
            delete(".backup");
            rename("", ".backup");
        }

        // 3. create filename.new, returning a stream for writing its content
        return new FilterOutputStream(write(".new")) {

            @Override
            public void close() throws IOException {
                super.close();
                rename(".new", "");
            }

        };
    }
项目:hustElectricity    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:Wetube    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:jephyr    文件:PGStream.java   
/**
 * Change the encoding used by this connection.
 *
 * @param encoding the new encoding to use
 * @throws IOException if something goes wrong
 */
public void setEncoding(Encoding encoding) throws IOException {
    // Close down any old writer.
    if (encodingWriter != null)
        encodingWriter.close();

    this.encoding = encoding;

    // Intercept flush() downcalls from the writer; our caller
    // will call PGStream.flush() as needed.
    OutputStream interceptor = new FilterOutputStream(pg_output) {
                                   public void flush() throws IOException {
                                   }
                                   public void close() throws IOException {
                                       super.flush();
                                   }
                               };

    encodingWriter = encoding.getEncodingWriter(interceptor);
}
项目:search    文件:SerializedDVStrategy.java   
@Override
public Field[] createIndexableFields(Shape shape) {
  int bufSize = Math.max(128, (int) (this.indexLastBufSize * 1.5));//50% headroom over last
  ByteArrayOutputStream byteStream = new ByteArrayOutputStream(bufSize);
  final BytesRef bytesRef = new BytesRef();//receiver of byteStream's bytes
  try {
    ctx.getBinaryCodec().writeShape(new DataOutputStream(byteStream), shape);
    //this is a hack to avoid redundant byte array copying by byteStream.toByteArray()
    byteStream.writeTo(new FilterOutputStream(null/*not used*/) {
      @Override
      public void write(byte[] b, int off, int len) throws IOException {
        bytesRef.bytes = b;
        bytesRef.offset = off;
        bytesRef.length = len;
      }
    });
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  this.indexLastBufSize = bytesRef.length;//cache heuristic
  return new Field[]{new BinaryDocValuesField(getFieldName(), bytesRef)};
}
项目:DemoArduinoAndroidCordovaBT    文件:HttpResponseCache.java   
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException {
  this.editor = editor;
  this.cacheOut = editor.newOutputStream(ENTRY_BODY);
  this.body = new FilterOutputStream(cacheOut) {
    @Override public void close() throws IOException {
      synchronized (HttpResponseCache.this) {
        if (done) {
          return;
        }
        done = true;
        writeSuccessCount++;
      }
      super.close();
      editor.commit();
    }

    @Override public void write(byte[] buffer, int offset, int length) throws IOException {
      // Since we don't override "write(int oneByte)", we can write directly to "out"
      // and avoid the inefficient implementation from the FilterOutputStream.
      out.write(buffer, offset, length);
    }
  };
}
项目:trading-singleleg    文件:ApiConnection.java   
@Override public synchronized void eConnect(Socket socket, int clientId) throws IOException {
    super.eConnect(socket, clientId);

    // replace the output stream with one that logs all data to m_outLogger
    if (isConnected()) {
        try {
            Field realOsField = FilterOutputStream.class.getDeclaredField( "out");
            realOsField.setAccessible( true);
            OutputStream realOs = (OutputStream)realOsField.get( m_dos);
            realOsField.set( m_dos, new MyOS( realOs) );
        }
        catch( Exception e) {
            e.printStackTrace();
        }
    }
}