@Override public InputStream getInputStream() { try { return (file != null ? new SelfClosingInputStream( new BufferedInputStream( new FileInputStream(file))) : dummyStream()); } catch (FileNotFoundException ex) { /* * Silently return null; validateFile has already logged a message * when the original caller tried to add this file to * the payload. */ return null; } }
@Override public int read() throws IOException { if (isExternallyClosed) { /* * The API does not permit reading after the stream * has been closed. Mimic that behavior. */ throw new IOException(); } if (isWrappedStreamClosed) { /* * We have closed the wrapped stream, because it * returned a -1 from read, but the stream has not * been externally closed yet. So continue returning * the end-of-stream indiciator. */ return -1; } final int result = wrappedStream.read(); if (result == -1) { /* * We've exhausted the wrapped stream, so close it * internally. */ closeInternally(); } return result; }
@Override public int read() throws IOException { if (isExternallyClosed) { /* * The API does not permit reading after the stream * has been closed. Mimic that behavior. */ throw new IOException(); } if (isWrappedStreamClosed) { /* * We have closed the wrapped stream, because it * returned a -1 from read, but the stream has not * been externally closed yet. So continue returning * the end-of-stream indiciator. */ return -1; } final int result = wrappedStream.read(); if (result == -1) { /* * We've exhausted the wrapped stream, so close it * internally. */ closeInternally(); } return result; }
@Override public int read() throws IOException { if (isExternallyClosed) { /* * The API does not permit reading after the stream * has been closed. Mimic that behavior. */ throw new IOException(); } if (isWrappedStreamClosed) { /* * We have closed the wrapped stream, because it * returned a -1 from read, but the stream has not * been externally closed yet. So continue returning * the end-of-stream indiciator. */ return -1; } final int result = wrappedStream.read(); if (result == -1) { /* * We've exhausted the wrapped stream, so close it * internally. */ closeInternally(); } return result; }
@Override public InputStream getInputStream() { try { return (file != null ? new SelfClosingInputStream( new BufferedInputStream( new FileInputStream(file))) : dummyStream()); } catch (FileNotFoundException ex) { /* * Silently return null; validateFile has already logged a message * when the original caller tried to add this file to * the payload. */ return null; } }
@Override public InputStream getInputStream() { try { return (file != null ? new SelfClosingInputStream( new BufferedInputStream( new FileInputStream(file))) : dummyStream()); } catch (FileNotFoundException ex) { /* * Silently return null; validateFile has already logged a message * when the original caller tried to add this file to * the payload. */ return null; } }
@Override public void close() throws IOException { closeInternally(); isExternallyClosed = true; }
@Override public void close() throws IOException { closeInternally(); isExternallyClosed = true; }
@Override public void close() throws IOException { closeInternally(); isExternallyClosed = true; }