@Override public void close() throws IOException { final FSDataOutputStream s = this.stream; if (s != null) { this.stream = null; s.close(); } }
/** * Reads library data from the given stream. * * @param in * the stream to read the library data from * @throws IOException * throws if an error occurs while reading from the stream */ private void readLibraryFromStreamInternal(final DataInput in) throws IOException { final String libraryFileName = StringRecord.readString(in); if (libraryFileName == null) { throw new IOException("libraryFileName is null!"); } final long length = in.readLong(); if (length > (long) Integer.MAX_VALUE) { throw new IOException("Submitted jar file " + libraryFileName + " is too large"); } final byte[] buf = new byte[(int) length]; in.readFully(buf); final Path storePath = new Path(this.libraryCachePath + "/" + libraryFileName); synchronized (this.fs) { // Check if file already exists in our library cache, if not write it to the cache directory if (!fs.exists(storePath)) { final FSDataOutputStream fos = fs.create(storePath, false); fos.write(buf, 0, buf.length); fos.close(); } } }
/** * Reads library data from the given stream. * * @param in * the stream to read the library data from * @throws IOException * throws if an error occurs while reading from the stream */ private void readLibraryFromStreamInternal(final DataInput in) throws IOException { final String libraryFileName = StringRecord.readString(in); if (libraryFileName == null) { throw new IOException("libraryFileName is null!"); } final long length = in.readLong(); if (length > (long) Integer.MAX_VALUE) { throw new IOException("Submitted jar file " + libraryFileName + " is too large"); } final byte[] buf = new byte[(int) length]; in.readFully(buf); final Path storePath = new Path(this.libraryCachePath + "/" + libraryFileName); synchronized (this.fs) { // Check if file already exists in our library cache, if not write it to the cache directory if (!fs.exists(storePath)) { final FSDataOutputStream fos = fs.create(storePath, false); fos.write(buf, 0, buf.length); fos.close(); } } }
@Override public void close() throws IOException { if (this.stream != null) { this.stream.write(this.buffer, 0, this.pos); } // close file stream super.close(); }
@Override public void close() throws IOException { final FSDataOutputStream s = this.stream; if (s != null) { this.stream = null; s.close(); } }
@Override public int write(final ByteBuffer src, final long position) throws IOException { if (position != this.nextExpectedWritePosition) { throw new IOException("Next expected write position is " + this.nextExpectedWritePosition); } final FSDataOutputStream outputStream = getOutputStream(); int totalBytesWritten = 0; while (src.hasRemaining()) { final int length = Math.min(this.buf.length, src.remaining()); src.get(this.buf, 0, length); outputStream.write(this.buf, 0, length); totalBytesWritten += length; } this.nextExpectedWritePosition += totalBytesWritten; return totalBytesWritten; }
/** * Double checked procedure setting the abort flag and closing the stream. */ private final void abortWait() { this.aborted = true; final FSDataOutputStream outStream = this.fdos; this.fdos = null; if (outStream != null) { try { outStream.close(); } catch (Throwable t) {} } } }
@Override public int write(final ByteBuffer src, final long position) throws IOException { if (position != this.nextExpectedWritePosition) { throw new IOException("Next expected write position is " + this.nextExpectedWritePosition); } final FSDataOutputStream outputStream = getOutputStream(); int totalBytesWritten = 0; while (src.hasRemaining()) { final int length = Math.min(this.buf.length, src.remaining()); src.get(this.buf, 0, length); outputStream.write(this.buf, 0, length); totalBytesWritten += length; } this.nextExpectedWritePosition += totalBytesWritten; return totalBytesWritten; }
/** * Double checked procedure setting the abort flag and closing the stream. */ private final void abortWait() { this.aborted = true; final FSDataOutputStream outStream = this.fdos; this.fdos = null; if (outStream != null) { try { outStream.close(); } catch (Throwable t) {} } } }
@Override protected void implCloseChannel() throws IOException { if (this.outputStream != null) { this.outputStream.close(); this.outputStream = null; } if (this.inputStream != null) { this.inputStream.close(); this.inputStream = null; } } }
@Override public void writeRecord(VertexWithRankAndDangling record) throws IOException { buffer.setLength(0); buffer.append(record.getVertexID()); buffer.append('\t'); buffer.append(record.getRank()); buffer.append('\n'); byte[] bytes = buffer.toString().getBytes(Charsets.UTF_8); stream.write(bytes); } }
@Override protected void implCloseChannel() throws IOException { if (this.outputStream != null) { this.outputStream.close(); this.outputStream = null; } if (this.inputStream != null) { this.inputStream.close(); this.inputStream = null; } } }
@Override public void writeRecord(Record record) throws IOException { buffer.setLength(0); buffer.append(record.getField(0, LongValue.class).toString()); buffer.append('\t'); buffer.append(record.getField(1, DoubleValue.class).toString()); buffer.append('\n'); byte[] bytes = buffer.toString().getBytes(Charsets.UTF_8); stream.write(bytes); } }
final FSDataOutputStream f = this.fdos; this.fdos = null; f.close();
@Override public void writeRecord(Record record) throws IOException { this.buffer.setLength(0); this.buffer.append(record.getField(0, keyString).toString()); this.buffer.append(' '); this.buffer.append(record.getField(1, valueInteger).getValue()); this.buffer.append('\n'); byte[] bytes = this.buffer.toString().getBytes(); LOG.debug("Writing out: [" + keyString.toString() + "," + valueInteger.getValue() + "]"); this.stream.write(bytes); } }