@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 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; }
@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; }
@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); } }
/** * 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(); } } }
fos.write(buf, 0, buf.length); fos.close();
fos.write(buf, 0, buf.length); fos.close();
@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); } }
@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(); if (LOG.isDebugEnabled()) LOG.debug("Writing out: [" + keyString.toString() + "," + valueInteger.getValue() + "]"); this.stream.write(bytes); } }
@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); } }
@Override public void writeRecord(Record record) throws IOException { int id = record.getField(0, IntValue.class).getValue(); Point p = record.getField(1, Point.class); byte[] bytes = String.format(format, id, p.x, p.y, p.z).getBytes(); this.stream.write(bytes); } }
@Override public void writeRecord(Record record) throws IOException { int id = record.getField(0, IntValue.class).getValue(); Point p = record.getField(1, Point.class); byte[] bytes = String.format(format, id, p.x, p.y, p.z).getBytes(); this.stream.write(bytes); } }
@Override public void writeRecord(Record record) throws IOException { key = record.getField(0, key); value = record.getField(1, value); this.buffer.setLength(0); this.buffer.append(key.getFirst().toString()); this.buffer.append('|'); this.buffer.append(key.getSecond().toString()); this.buffer.append('|'); this.buffer.append(value.toString()); this.buffer.append('\n'); byte[] bytes = this.buffer.toString().getBytes(); this.stream.write(bytes); }
@Override public void writeRecord(Record record) throws IOException { this.buffer.setLength(0); this.buffer.append(record.getField(0, IntValue.class).toString()).append('|'); this.buffer.append(record.getField(1, StringValue.class).toString()).append('|'); this.buffer.append(this.formatter.format(record.getField(2, DoubleValue.class).getValue())).append('|'); this.buffer.append(record.getField(3, StringValue.class).toString()).append('|'); this.buffer.append(record.getField(4, StringValue.class).toString()).append('|'); this.buffer.append(record.getField(5, StringValue.class).toString()).append('|'); this.buffer.append(record.getField(6, StringValue.class).toString()).append('|'); this.buffer.append(record.getField(7, StringValue.class).toString()).append('|'); this.buffer.append('\n'); final byte[] bytes = this.buffer.toString().getBytes(); this.stream.write(bytes); } }
@Override public void writeRecord(Record record) throws IOException { StringBuilder line = new StringBuilder(); // append from-node line.append(record.getField(0, StringValue.class).toString()); line.append("|"); // append to-node line.append(record.getField(1, StringValue.class).toString()); line.append("|"); // append length line.append(record.getField(2, IntValue.class).toString()); line.append("|"); // append hopCnt line.append(record.getField(3, IntValue.class).toString()); line.append("|"); // append hopList line.append(record.getField(4, StringValue.class).toString()); line.append("|"); line.append("\n"); stream.write(line.toString().getBytes()); } }
@Override public void writeRecord(Record record) throws IOException { record.getField(0, TeraKey.class).copyToBuffer(this.buffer); record.getField(1, TeraValue.class).copyToBuffer(this.buffer); this.buffer[TeraKey.KEY_SIZE + TeraValue.VALUE_SIZE] = '\n'; this.stream.write(buffer, 0, buffer.length); }
lfsoutput1.write(testbytes); lfsoutput1.close();