@Override public void flush() throws IOException { outputStream.flush(); }
@Override public void flush() throws IOException { out.flush(); }
@Override public void flush() throws IOException { try { originalStream.flush(); } catch (IOException e) { handleIOException(e); } }
@Override public void flush() throws IOException { stream.flush(); }
@Test public void testDelegateOutStreamMethods() throws IOException { // mock the output stream final FSDataOutputStream mockOut = mock(FSDataOutputStream.class); final long outPos = 46651L; when(mockOut.getPos()).thenReturn(outPos); final FileSystem fs = mock(FileSystem.class); when(fs.create(any(Path.class), any(WriteMode.class))).thenReturn(mockOut); final LimitedConnectionsFileSystem lfs = new LimitedConnectionsFileSystem(fs, 100); final FSDataOutputStream out = lfs.create(mock(Path.class), WriteMode.OVERWRITE); // validate the output stream out.write(77); verify(mockOut).write(77); { byte[] bytes = new byte[1786]; out.write(bytes, 100, 111); verify(mockOut).write(bytes, 100, 111); } assertEquals(outPos, out.getPos()); out.flush(); verify(mockOut).flush(); out.sync(); verify(mockOut).sync(); out.close(); verify(mockOut).close(); }
@Test public void testWithSafetyNet() throws Exception { final String entropyKey = "__ekey__"; final String entropyValue = "abc"; final File folder = TMP_FOLDER.newFolder(); final Path path = new Path(Path.fromLocalFile(folder), entropyKey + "/path/"); final Path pathWithEntropy = new Path(Path.fromLocalFile(folder), entropyValue + "/path/"); TestEntropyInjectingFs efs = new TestEntropyInjectingFs(entropyKey, entropyValue); FSDataOutputStream out; FileSystemSafetyNet.initializeSafetyNetForThread(); FileSystem fs = FileSystemSafetyNet.wrapWithSafetyNetWhenActivated(efs); try { OutputStreamAndPath streamAndPath = EntropyInjector.createEntropyAware( fs, path, WriteMode.NO_OVERWRITE); out = streamAndPath.stream(); assertEquals(pathWithEntropy, streamAndPath.path()); } finally { FileSystemSafetyNet.closeSafetyNetAndGuardedResourcesForThread(); } // check that the safety net closed the stream try { out.write(42); out.flush(); fail("stream should be already close and hence fail with an exception"); } catch (IOException ignored) {} }
@Override public void flush() throws IOException { out.flush(); }
@Override public void flush() throws IOException { outputStream.flush(); }
@Override public void flush() throws IOException { out.flush(); }
@Override public void flush() throws IOException { outputStream.flush(); }
@Override public void flush() throws IOException { out.flush(); }
@Override public void flush() throws IOException { out.flush(); }
@Override public void flush() throws IOException { out.flush(); }
@Override public void flush() throws IOException { out.flush(); }
@Override public void flush() throws IOException { try { originalStream.flush(); } catch (IOException e) { handleIOException(e); } }
@Override public void flush() throws IOException { try { originalStream.flush(); } catch (IOException e) { handleIOException(e); } }