java.io.FilterOutputStream Java Examples
The following examples show how to use
java.io.FilterOutputStream.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 8 votes |
@Override public OutputStream createFile(String f) throws FileSystemException, IOException { Set<AccessMask> accessMask = new HashSet<AccessMask>(EnumSet.of(AccessMask.FILE_ADD_FILE)); Set<SMB2CreateOptions> createOptions = new HashSet<SMB2CreateOptions>( EnumSet.of(SMB2CreateOptions.FILE_NON_DIRECTORY_FILE, SMB2CreateOptions.FILE_WRITE_THROUGH)); final File file = diskShare.openFile(f, accessMask, null, SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OVERWRITE_IF, createOptions); OutputStream out = file.getOutputStream(); FilterOutputStream fos = new FilterOutputStream(out) { boolean isOpen = true; @Override public void close() throws IOException { if(isOpen) { super.close(); isOpen=false; } file.close(); } }; return fos; }
Example #2
Source File: FileObject75826Test.java From netbeans with Apache License 2.0 | 6 votes |
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()); }
Example #3
Source File: OldFilterOutputStreamTest.java From j2objc with Apache License 2.0 | 6 votes |
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. } }
Example #4
Source File: HttpResponseCache.java From wildfly-samples with MIT License | 6 votes |
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); } }; }
Example #5
Source File: MeteredOutputStream.java From incubator-gobblin with Apache License 2.0 | 6 votes |
/** * Find the lowest {@link MeteredOutputStream} in a chain of {@link FilterOutputStream}s. */ public static Optional<MeteredOutputStream> findWrappedMeteredOutputStream(OutputStream os) { if (os instanceof FilterOutputStream) { try { Optional<MeteredOutputStream> meteredOutputStream = findWrappedMeteredOutputStream(FilterStreamUnpacker.unpackFilterOutputStream((FilterOutputStream) os)); if (meteredOutputStream.isPresent()) { return meteredOutputStream; } } catch (IllegalAccessException iae) { log.warn("Cannot unpack input stream due to SecurityManager.", iae); // Do nothing, we can't unpack the FilterInputStream due to security restrictions } } if (os instanceof MeteredOutputStream) { return Optional.of((MeteredOutputStream) os); } return Optional.absent(); }
Example #6
Source File: HttpResponseCache.java From phonegap-plugin-loading-spinner with Apache License 2.0 | 6 votes |
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); } }; }
Example #7
Source File: MongoRepositoryItem.java From kurento-java with Apache License 2.0 | 6 votes |
@Override public OutputStream createOutputStreamToWrite() { checkState(State.NEW); storingOutputStream = new FilterOutputStream(((GridFSInputFile) dbFile).getOutputStream()) { @Override public void close() throws IOException { putMetadataInGridFS(false); super.close(); refreshAttributesOnClose(); } }; return storingOutputStream; }
Example #8
Source File: FHIRJsonGenerator.java From FHIR with Apache License 2.0 | 6 votes |
/** * Temporary workaround for: https://github.com/eclipse-ee4j/jsonp/issues/190 */ private OutputStream wrap(OutputStream out) { return new FilterOutputStream(out) { private boolean first = true; @Override public void write(int b) throws IOException { if (first && b == '\n') { first = false; return; } out.write(b); } @Override public void close() { // do nothing } }; }
Example #9
Source File: FileRepositoryItem.java From kurento-java with Apache License 2.0 | 6 votes |
@Override public OutputStream createOutputStreamToWrite() { checkState(State.NEW); try { this.state = State.STORING; storingOutputStream = new FilterOutputStream(new FileOutputStream(file)) { @Override public void close() throws java.io.IOException { refreshAttributesOnClose(); } }; return storingOutputStream; } catch (FileNotFoundException e) { throw new KurentoException("There is a problem opening the output stream to the file " + "that will store the contents of the repositoty item", e); } }
Example #10
Source File: HttpResponseCache.java From cordova-android-chromeview with Apache License 2.0 | 6 votes |
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); } }; }
Example #11
Source File: UnixSocket.java From jkube with Eclipse Public License 2.0 | 6 votes |
@Override public OutputStream getOutputStream() throws IOException { if (!channel.isOpen()) { throw new SocketException("Socket is closed"); } if (!channel.isConnected()) { throw new SocketException("Socket is not connected"); } if (outputShutdown) { throw new SocketException("Socket output is shutdown"); } return new FilterOutputStream(Channels.newOutputStream(channel)) { @Override public void write(byte[] b, int off, int len) throws IOException { out.write(b, off, len); } @Override public void close() throws IOException { shutdownOutput(); } }; }
Example #12
Source File: HttpResponseCache.java From reader with MIT License | 6 votes |
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); } }; }
Example #13
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 6 votes |
@Override public OutputStream appendFile(String f) throws FileSystemException, IOException { final File file = getFile(f, AccessMask.FILE_APPEND_DATA, SMB2CreateDisposition.FILE_OPEN_IF); OutputStream out = file.getOutputStream(); FilterOutputStream fos = new FilterOutputStream(out) { boolean isOpen = true; @Override public void close() throws IOException { if(isOpen) { super.close(); isOpen=false; } file.close(); } }; return fos; }
Example #14
Source File: HttpResponseCache.java From cordova-amazon-fireos with Apache License 2.0 | 6 votes |
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); } }; }
Example #15
Source File: PropertiesStorage.java From netbeans with Apache License 2.0 | 6 votes |
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(); } }; }
Example #16
Source File: HttpResponseCache.java From CordovaYoutubeVideoPlayer with MIT License | 6 votes |
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); } }; }
Example #17
Source File: LocalFileSystem.java From netbeans with Apache License 2.0 | 6 votes |
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; }
Example #18
Source File: HttpResponseCache.java From cordova-android-chromeview with Apache License 2.0 | 6 votes |
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); } }; }
Example #19
Source File: SerializationUtil.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 6 votes |
static public <S extends Serializable> void serialize(S object, OutputStream os) throws IOException { FilterOutputStream safeOs = new FilterOutputStream(os){ @Override public void close() throws IOException { super.flush(); } }; try(ObjectOutputStream oos = new ObjectOutputStream(safeOs)){ oos.writeObject(object); oos.flush(); } }
Example #20
Source File: HttpResponseCache.java From bluemix-parking-meter with MIT License | 6 votes |
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); } }; }
Example #21
Source File: HttpResponseCache.java From android-discourse with Apache License 2.0 | 6 votes |
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); } }; }
Example #22
Source File: ToolBox.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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); } }); } }; }
Example #23
Source File: AbstractRestApiTask.java From database with GNU General Public License v2.0 | 6 votes |
/** * Return the {@link ServletOutputStream} associated with the request (and * stash a copy). * * @throws IOException * @throws IllegalStateException * per the servlet API if the writer has been requested already. */ public OutputStream getOutputStream() throws IOException { lock.lock(); try { return new FilterOutputStream(this.os = resp.getOutputStream()) { @Override public void flush() { throw new UnsupportedOperationException(); } @Override public void close() { throw new UnsupportedOperationException(); } }; } finally { lock.unlock(); } }
Example #24
Source File: HttpResponseCache.java From IoTgo_Android_App with MIT License | 6 votes |
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); } }; }
Example #25
Source File: SingleStreamCodeWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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 } }; }
Example #26
Source File: UnixSocket.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
@Override public OutputStream getOutputStream() throws IOException { if (!channel.isOpen()) { throw new SocketException("Socket is closed"); } if (!channel.isConnected()) { throw new SocketException("Socket is not connected"); } if (outputShutdown) { throw new SocketException("Socket output is shutdown"); } return new FilterOutputStream(Channels.newOutputStream(channel)) { @Override public void write(byte[] b, int off, int len) throws IOException { out.write(b, off, len); } @Override public void close() throws IOException { shutdownOutput(); } }; }
Example #27
Source File: UnownedOutputStreamTest.java From beam with Apache License 2.0 | 6 votes |
@Test public void testWrite() throws IOException { CallCountOutputStream fsCount = new CallCountOutputStream(); FilterOutputStream fs = new FilterOutputStream(fsCount); CallCountOutputStream osCount = new CallCountOutputStream(); UnownedOutputStream os = new UnownedOutputStream(osCount); byte[] data = "Hello World!".getBytes(StandardCharsets.UTF_8); fs.write(data, 0, data.length); os.write(data, 0, data.length); fs.write('\n'); os.write('\n'); assertEquals(13, fsCount.callCnt); assertEquals(2, osCount.callCnt); assertArrayEquals(fsCount.toByteArray(), osCount.toByteArray()); }
Example #28
Source File: OutputCommand.java From commons-rng with Apache License 2.0 | 6 votes |
/** * Creates the output stream. This will not be buffered. * * @return the output stream */ private OutputStream createOutputStream() { if (fileOutput != null) { try { Files.newOutputStream(fileOutput.toPath()); } catch (IOException ex) { throw new ApplicationException("Failed to create output: " + fileOutput, ex); } } return new FilterOutputStream(System.out) { @Override public void close() { // Do not close stdout } }; }
Example #29
Source File: ResultsCommand.java From commons-rng with Apache License 2.0 | 6 votes |
/** * Creates the output stream. This will not be buffered. * * @return the output stream */ private OutputStream createOutputStream() { if (fileOutput != null) { try { Files.newOutputStream(fileOutput.toPath()); } catch (final IOException ex) { throw new ApplicationException("Failed to create output: " + fileOutput, ex); } } return new FilterOutputStream(System.out) { @Override public void close() { // Do not close stdout } }; }
Example #30
Source File: SerializedDVStrategy.java From lucene-solr with Apache License 2.0 | 6 votes |
@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)}; }