/** * Writing the value to the output stream. This method avoids copying * value data from Scanner into user buffer, then writing to the output * stream. It does not require the value length to be known. * * @param out * The output stream * @return the length of the value * @throws IOException */ public long writeValue(OutputStream out) throws IOException { DataInputStream dis = getValueStream(); long size = 0; try { int chunkSize; while ((chunkSize = valueBufferInputStream.getRemain()) > 0) { chunkSize = Math.min(chunkSize, MAX_VAL_TRANSFER_BUF_SIZE); valTransferBuffer.setSize(chunkSize); dis.readFully(valTransferBuffer.getBytes(), 0, chunkSize); out.write(valTransferBuffer.getBytes(), 0, chunkSize); size += chunkSize; } return size; } finally { dis.close(); } }
DataInputStream dis = getValueStream(); try { if (isValueLengthKnown()) {
/** * Copy the value into BytesWritable. The input BytesWritable will be * automatically resized to the actual value size. The implementation * directly uses the buffer inside BytesWritable for storing the value. * The call does not require the value length to be known. * * @param value * @throws IOException */ public long getValue(BytesWritable value) throws IOException { DataInputStream dis = getValueStream(); int size = 0; try { int remain; while ((remain = valueBufferInputStream.getRemain()) > 0) { value.setSize(size + remain); dis.readFully(value.getBytes(), size, remain); size += remain; } return value.getLength(); } finally { dis.close(); } }
/** * Copy the value into BytesWritable. The input BytesWritable will be * automatically resized to the actual value size. The implementation * directly uses the buffer inside BytesWritable for storing the value. * The call does not require the value length to be known. * * @param value * @throws IOException */ public long getValue(BytesWritable value) throws IOException { DataInputStream dis = getValueStream(); int size = 0; try { int remain; while ((remain = valueBufferInputStream.getRemain()) > 0) { value.setSize(size + remain); dis.readFully(value.getBytes(), size, remain); size += remain; } return value.getLength(); } finally { dis.close(); } }
/** * Read the next key and return the value-stream. * * @param key * @return the valueStream if there are more keys or null otherwise. * @throws IOException */ public DataInputStream next(LogKey key) throws IOException { if (!this.atBeginning) { this.scanner.advance(); } else { this.atBeginning = false; } if (this.scanner.atEnd()) { return null; } TFile.Reader.Scanner.Entry entry = this.scanner.entry(); key.readFields(entry.getKeyStream()); // Skip META keys if (RESERVED_KEYS.containsKey(key.toString())) { return next(key); } DataInputStream valueStream = entry.getValueStream(); return valueStream; }
/** * Read the next key and return the value-stream. * * @param key * @return the valueStream if there are more keys or null otherwise. * @throws IOException */ public DataInputStream next(LogKey key) throws IOException { if (!this.atBeginning) { this.scanner.advance(); } else { this.atBeginning = false; } if (this.scanner.atEnd()) { return null; } TFile.Reader.Scanner.Entry entry = this.scanner.entry(); key.readFields(entry.getKeyStream()); // Skip META keys if (RESERVED_KEYS.containsKey(key.toString())) { return next(key); } DataInputStream valueStream = entry.getValueStream(); return valueStream; }
/** * Returns the owner of the application. * * @return the application owner. * @throws IOException if we can not get the application owner. */ public String getApplicationOwner() throws IOException { TFile.Reader.Scanner ownerScanner = null; try { ownerScanner = reader.createScanner(); LogKey key = new LogKey(); while (!ownerScanner.atEnd()) { TFile.Reader.Scanner.Entry entry = ownerScanner.entry(); key.readFields(entry.getKeyStream()); if (key.toString().equals(APPLICATION_OWNER_KEY.toString())) { DataInputStream valueStream = entry.getValueStream(); return valueStream.readUTF(); } ownerScanner.advance(); } return null; } finally { IOUtils.cleanupWithLogger(LOG, ownerScanner); } }
public boolean nextKeyValue() throws IOException { // skip to next record if (scanner.atEnd()) { value = null; return false; } DataInputStream in = scanner.entry().getValueStream(); try { // if we got here, we have seen RECORD_1-RECORD_2-RECORD_3-TUPLE_MARKER // sequence - lets now read the contents of the tuple value = (Tuple) sedes.readDatum(in); } finally { in.close(); } scanner.advance(); return true; }
/** * Returns the owner of the application. * * @return the application owner. * @throws IOException */ public String getApplicationOwner() throws IOException { TFile.Reader.Scanner ownerScanner = reader.createScanner(); LogKey key = new LogKey(); while (!ownerScanner.atEnd()) { TFile.Reader.Scanner.Entry entry = ownerScanner.entry(); key.readFields(entry.getKeyStream()); if (key.toString().equals(APPLICATION_OWNER_KEY.toString())) { DataInputStream valueStream = entry.getValueStream(); return valueStream.readUTF(); } ownerScanner.advance(); } return null; }
/** * Returns the owner of the application. * * @return the application owner. * @throws IOException */ public String getApplicationOwner() throws IOException { TFile.Reader.Scanner ownerScanner = reader.createScanner(); LogKey key = new LogKey(); while (!ownerScanner.atEnd()) { TFile.Reader.Scanner.Entry entry = ownerScanner.entry(); key.readFields(entry.getKeyStream()); if (key.toString().equals(APPLICATION_OWNER_KEY.toString())) { DataInputStream valueStream = entry.getValueStream(); return valueStream.readUTF(); } ownerScanner.advance(); } return null; }
/** * Writes the contents of the entry into the given outputWriter * * @param outputWriter * @throws IOException */ public void write(final Writer outputWriter) throws IOException { try (final DataInputStream keyStream = entry.getKeyStream(); final DataInputStream valueStream = entry.getValueStream();) { outputWriter.write("Container: "); outputWriter.write(keyStream.readUTF()); outputWriter.write("\n"); this.writeFiles(valueStream, outputWriter); } }
/** * Writes the logs stored in the entry as text files in folder, one per container. * * @param folder * @throws IOException */ public void write(final File folder) throws IOException { try (final DataInputStream keyStream = entry.getKeyStream(); final DataInputStream valueStream = entry.getValueStream();) { final String containerId = keyStream.readUTF(); try (final Writer outputWriter = new FileWriter(new File(folder, containerId + ".txt"))) { this.writeFiles(valueStream, outputWriter); } } }
/** * Writes the logs stored in the entry as text files in folder, one per container. * * @param folder * @throws IOException */ public void write(final File folder) throws IOException { try (final DataInputStream keyStream = entry.getKeyStream(); final DataInputStream valueStream = entry.getValueStream();) { final String containerId = keyStream.readUTF(); try (final Writer outputWriter = new OutputStreamWriter( new FileOutputStream(new File(folder, containerId + ".txt")), StandardCharsets.UTF_8)) { this.writeFiles(valueStream, outputWriter); } } }
/** * Writes the contents of the entry into the given outputWriter. * * @param outputWriter * @throws IOException */ public void write(final Writer outputWriter) throws IOException { try (final DataInputStream keyStream = entry.getKeyStream(); final DataInputStream valueStream = entry.getValueStream();) { outputWriter.write("Container: "); outputWriter.write(keyStream.readUTF()); outputWriter.write("\n"); this.writeFiles(valueStream, outputWriter); } }
public byte[] readLongValue(Scanner scanner, int len) throws IOException { DataInputStream din = scanner.entry().getValueStream(); byte[] b = new byte[len]; din.readFully(b); din.close(); return b; }
public Entry next() throws IOException { TFile.Reader.Scanner.Entry entry = scanner.entry(); DataInputStream dis = entry.getKeyStream(); HistoryDataKey key = new HistoryDataKey(); key.readFields(dis); dis = entry.getValueStream(); byte[] value = new byte[entry.getValueLength()]; dis.read(value); scanner.advance(); return new Entry(key, value); }
public Entry next() throws IOException { TFile.Reader.Scanner.Entry entry = scanner.entry(); DataInputStream dis = entry.getKeyStream(); HistoryDataKey key = new HistoryDataKey(); key.readFields(dis); dis = entry.getValueStream(); byte[] value = new byte[entry.getValueLength()]; dis.read(value); scanner.advance(); return new Entry(key, value); }
public Entry next() throws IOException { TFile.Reader.Scanner.Entry entry = scanner.entry(); DataInputStream dis = entry.getKeyStream(); HistoryDataKey key = new HistoryDataKey(); key.readFields(dis); dis = entry.getValueStream(); byte[] value = new byte[entry.getValueLength()]; dis.read(value); scanner.advance(); return new Entry(key, value); }
public byte[] readLongValue(Scanner scanner, int len) throws IOException { DataInputStream din = scanner.entry().getValueStream(); byte[] b = new byte[len]; din.readFully(b); din.close(); return b; }
public byte[] readLongValue(Scanner scanner, int len) throws IOException { DataInputStream din = scanner.entry().getValueStream(); byte[] b = new byte[len]; din.readFully(b); din.close(); return b; }