本文整理匯總了Java中java.io.FilterOutputStream類的典型用法代碼示例。如果您正苦於以下問題:Java FilterOutputStream類的具體用法?Java FilterOutputStream怎麽用?Java FilterOutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FilterOutputStream類屬於java.io包,在下文中一共展示了FilterOutputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: openBinary
import java.io.FilterOutputStream; //導入依賴的package包/類
@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"));
}
};
}
示例2: openBinary
import java.io.FilterOutputStream; //導入依賴的package包/類
@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"));
}
};
}
示例3: openBinary
import java.io.FilterOutputStream; //導入依賴的package包/類
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);
}
};
}
示例4: outputStream
import java.io.FilterOutputStream; //導入依賴的package包/類
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();
}
};
}
示例5: getOutputStreamForMac42624
import java.io.FilterOutputStream; //導入依賴的package包/類
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;
}
示例6: TestFileSystem
import java.io.FilterOutputStream; //導入依賴的package包/類
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());
}
示例7: getOutputStream
import java.io.FilterOutputStream; //導入依賴的package包/類
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());
}
};
}
示例8: CacheRequestImpl
import java.io.FilterOutputStream; //導入依賴的package包/類
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);
}
};
}
示例9: openOutputStream
import java.io.FilterOutputStream; //導入依賴的package包/類
@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);
}
});
}
};
}
示例10: openBinary
import java.io.FilterOutputStream; //導入依賴的package包/類
@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
}
};
}
示例11: eConnect
import java.io.FilterOutputStream; //導入依賴的package包/類
@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();
}
}
}
示例12: test_flush
import java.io.FilterOutputStream; //導入依賴的package包/類
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);
}
示例13: Support_OutputStream
import java.io.FilterOutputStream; //導入依賴的package包/類
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.
}
}
示例14: test_writeI
import java.io.FilterOutputStream; //導入依賴的package包/類
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.
}
}
示例15: writeWithBackup
import java.io.FilterOutputStream; //導入依賴的package包/類
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", "");
}
};
}