@Override public void write(byte[] buffer, int off, int len) throws IOException { out.write(buffer, off, len); }
@Override public void write(int b) throws IOException { outputStream.write(b); }
@Override public void write(int b) throws IOException { out.write(b); }
@Override public void write(byte[] b) throws IOException { outputStream.write(b); }
@Override public void write(byte[] b, int off, int len) throws IOException { outputStream.write(b, off, len); }
@Override public void write(byte[] b, int off, int len) throws IOException { try { originalStream.write(b, off, len); } catch (IOException e) { handleIOException(e); } }
@Override public void write(int b) throws IOException { try { originalStream.write(b); } catch (IOException e) { handleIOException(e); } }
@Override public void addElement(Tuple2<String, Integer> element) throws IOException { stream.write((element.f0 + '@' + element.f1 + '\n').getBytes(CHARSET)); }
private void createFile(Path file) throws IOException { try (FSDataOutputStream out = fs.create(file, WriteMode.NO_OVERWRITE)) { out.write(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); } }
@Override public void go() throws Exception { try (FSDataOutputStream stream = fs.create(path, WriteMode.OVERWRITE)) { assertTrue(fs.getNumberOfOpenOutputStreams() <= maxConcurrentOutputStreams); assertTrue(fs.getTotalNumberOfOpenStreams() <= maxConcurrentStreamsTotal); final Random rnd = new Random(); final byte[] data = new byte[rnd.nextInt(10000) + 1]; rnd.nextBytes(data); stream.write(data); waitTillWokenUp(); // try to write one more thing, which might/should fail with an I/O exception stream.write(rnd.nextInt()); } } }
@Override public void go() throws Exception { try (FSDataOutputStream stream = fs.create(path, WriteMode.OVERWRITE)) { assertTrue(fs.getNumberOfOpenOutputStreams() <= maxConcurrentOutputStreams); assertTrue(fs.getTotalNumberOfOpenStreams() <= maxConcurrentStreamsTotal); final Random rnd = new Random(); final byte[] data = new byte[rnd.nextInt(10000) + 1]; rnd.nextBytes(data); stream.write(data); } } }
@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(); }
@Override public void go() throws Exception { fs.initOutPathLocalFS(path.getParent(), WriteMode.OVERWRITE, true); try (FSDataOutputStream out = fs.create(path, WriteMode.OVERWRITE)) { out.write(11); } } }
out.write(bytesLeft); Thread.sleep(5);
outputStream.write(buffer, 0, numBytes);
lfsoutput1.write(testbytes); lfsoutput1.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) {} }
private void createFile(Path path, boolean overwrite) throws IOException { final WriteMode writeMode = overwrite ? WriteMode.OVERWRITE : WriteMode.NO_OVERWRITE; try (FSDataOutputStream out = fileSystem.create(path, writeMode)) { out.write(42); } } }
@Override public void write(byte[] b, int off, int len) throws IOException { try { originalStream.write(b, off, len); } catch (IOException e) { handleIOException(e); } }