private void closeQuietly(DataFileStream<GenericRecord> stream) { try { if (stream != null) { stream.close(); } } catch (IOException ignored) { } } }
@Override public void writeRecord(E record) throws IOException { dataFileWriter.append(record); }
void close() throws IOException { mAvroFileWriter.close(); }
Codec resolveCodec() { String codecStr = getMetaString(DataFileConstants.CODEC); if (codecStr != null) { return CodecFactory.fromString(codecStr).createInstance(); } else { return CodecFactory.nullCodec().createInstance(); } }
@Override public void close() throws IOException { if (isEmptyInput == false) reader.close(); }
/** * Configures this writer to use the given codec. * May not be reset after writes have begun. */ public DataFileWriter<D> setCodec(CodecFactory c) { assertNotOpen(); this.codec = c.createInstance(); setMetaInternal(DataFileConstants.CODEC, codec.getName()); return this; }
/** Open a writer appending to an existing file. */ public DataFileWriter<D> appendTo(File file) throws IOException { SeekableInput input = null; try { input = new SeekableFileInput(file); OutputStream output = new SyncableFileOutputStream(file, true); return appendTo(input, output); } finally { if (input != null) input.close(); // output does not need to be closed here. It will be closed by invoking close() of this writer. } }
/** Open a writer appending to an existing file. */ public DataFileWriter<D> appendTo(File file) throws IOException { return appendTo(new SeekableFileInput(file), new SyncableFileOutputStream(file, true)); }
long sync() throws IOException { return mAvroFileWriter.sync(); } }
/** Construct a reader for a file. */ public DataFileReader(SeekableInput sin, DatumReader<D> reader) throws IOException { super(reader); this.sin = new SeekableInputStream(sin); initialize(this.sin); blockFinished(); }
/** Construct using a {@link DataFileStream.Header}. Does not call {@link #sync(long)} or {@link #seek(long)}. */ protected DataFileReader(SeekableInput sin, DatumReader<D> reader, Header header) throws IOException { super(reader); this.sin = new SeekableInputStream(sin); initialize(this.sin, header); }
@Override public String toString() { Codec instance = this.createInstance(); return instance.toString(); }
void write(K key, V value) throws IOException { mOutputRecord.setKey(key); mOutputRecord.setValue(value); mAvroFileWriter.append(mOutputRecord.get()); }
Codec resolveCodec() { String codecStr = getMetaString(DataFileConstants.CODEC); if (codecStr != null) { return CodecFactory.fromString(codecStr).createInstance(); } else { return CodecFactory.nullCodec().createInstance(); } }
@Override public void close() throws IOException { _avroReader.close(); } }
/** * Configures this writer to use the given codec. * May not be reset after writes have begun. */ public DataFileWriter<D> setCodec(CodecFactory c) { assertNotOpen(); this.codec = c.createInstance(); setMetaInternal(DataFileConstants.CODEC, codec.getName()); return this; }