@Override public void flush() throws IOException { if (dataFileWriter != null) { dataFileWriter.flush(); } }
/** * Flush the writer * @throws IOException */ @Override public void flush() throws IOException { this.writer.flush(); } }
@Override public void flush() throws IOException { writer.flush(); }
@Override public void flush() throws IOException { dataFileWriter.flush(); }
@Override public void flush() throws IOException { dataFileWriter.flush(); }
@Override public void flush() throws IOException { dataFileWriter.flush(); }
/** Flush and close the file. */ @Override public void close() throws IOException { if (isOpen) { flush(); out.close(); isOpen = false; } }
@Override protected void doSync() throws IOException { avroWriter.flush(); LOG.debug("Attempting to sync all data to filesystem"); if (this.out instanceof HdfsDataOutputStream) { ((HdfsDataOutputStream) this.out).hsync(EnumSet.of(HdfsDataOutputStream.SyncFlag.UPDATE_LENGTH)); } else { this.out.hsync(); } }
/** Flush and close the file. */ @Override public void close() throws IOException { if (isOpen) { flush(); out.close(); isOpen = false; } }
/** * If this writer was instantiated using a File or using an * {@linkplain Syncable} instance, this method flushes all buffers for this * writer to disk. In other cases, this method behaves exactly * like {@linkplain #flush()}. * * @throws IOException */ public void fSync() throws IOException { flush(); if (underlyingStream instanceof Syncable) { ((Syncable) underlyingStream).sync(); } }
/** * If this writer was instantiated using a File or using an * {@linkplain Syncable} instance, this method flushes all buffers for this * writer to disk. In other cases, this method behaves exactly * like {@linkplain #flush()}. * * @throws IOException */ public void fSync() throws IOException { flush(); if (underlyingStream instanceof Syncable) { ((Syncable) underlyingStream).sync(); } }
@Override public void close() throws IOException { dataFileWriter.flush(); dataFileWriter.close(); super.close(); } }
@Override public synchronized void storePosition(long position) throws IOException { metaCache.setOffset(position); writer.append(metaCache); writer.sync(); writer.flush(); }
@Override public byte[] serialise(final Object object) throws SerialisationException { Schema schema = ReflectData.get().getSchema(object.getClass()); DatumWriter<Object> datumWriter = new ReflectDatumWriter<>(schema); DataFileWriter<Object> dataFileWriter = new DataFileWriter<>(datumWriter); ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); try { dataFileWriter.create(schema, byteOut); dataFileWriter.append(object); dataFileWriter.flush(); } catch (final IOException e) { throw new SerialisationException("Unable to serialise given object of class: " + object.getClass().getName(), e); } finally { close(dataFileWriter); } return byteOut.toByteArray(); }
writer.flush(); } finally { writer.close();
writer.flush();
private void writeOneXAsAvro(Schema schema, ByteArrayOutputStream bout) throws IOException, FileNotFoundException { DatumWriter<X> datumWriter = new ReflectDatumWriter<>(schema); try(DataFileWriter<X> writer = new DataFileWriter<>(datumWriter)) { writer.create(schema, bout); X x = new X(); x.name = "xxx"; try (FileInputStream fis = new FileInputStream(content)) { try (FileChannel channel = fis.getChannel()) { long contentLength = content.length(); //set the content to be a file channel. ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, contentLength); x.content = buffer; writer.append(x); } } writer.flush(); } }
@Test public void testNoWritingAfterException() throws IOException { DataFileWriter<Object> writer = new DataFileWriter<Object>(new GenericDatumWriter<Object>()); try { writer.create(SCHEMA, new FailingOutputStream(100000)); int recordCnt = 0; for (Object datum : new RandomData(SCHEMA, 100000, 42)) { writer.append(datum); if (++recordCnt % 17 == 0) { writer.flush(); } } } catch (IOException e) { return; } finally { writer.close(); } fail("IOException should have been thrown"); }
if (currentCount % 10 == 0) { flushCounter++; writer.flush();
@Test public void testAvroEvolvedRead() throws IOException { File serializedAvro = File.createTempFile("avro", null); DatumWriter<GenericRecord> dw = new GenericDatumWriter<>(writer); DataFileWriter<GenericRecord> dfw = new DataFileWriter<>(dw); dfw.create(writer, serializedAvro); dfw.append(writtenRecord); dfw.flush(); dfw.close(); GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(writer); reader.setExpected(evolved); DataFileReader<GenericRecord> dfr = new DataFileReader<>(serializedAvro, reader); GenericRecord readRecord = dfr.next(); Assert.assertEquals(evolvedRecord, readRecord); Assert.assertFalse(dfr.hasNext()); }