avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1339841 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
Date Thu, 17 May 2012 20:16:07 GMT
Author: cutting
Date: Thu May 17 20:16:07 2012
New Revision: 1339841

URL: http://svn.apache.org/viewvc?rev=1339841&view=rev
Log:
AVRO-1090. Java: Permit appending to files besides java.io.File, e.g., files in HDFS.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1339841&r1=1339840&r2=1339841&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu May 17 20:16:07 2012
@@ -35,6 +35,9 @@ Avro 1.7.0 (unreleased)
     AVRO-1062. Java: Remove use of java.rmi.server.UID so things work
     on Android.  (Kevin Zhao via cutting)
 
+    AVRO-1090. Java: Permit appending to files besides java.io.File,
+    e.g., files in HDFS. (cutting)
+
   BUG FIXES
 
     AVRO-1045. Java: Fix a bug in GenericData#deepCopy() of ByteBuffer values.

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java?rev=1339841&r1=1339840&r2=1339841&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java Thu May
17 20:16:07 2012
@@ -21,14 +21,11 @@ import java.io.BufferedOutputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
 import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FilterOutputStream;
 import java.io.Flushable;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.io.RandomAccessFile;
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.security.MessageDigest;
@@ -149,14 +146,19 @@ public class DataFileWriter<D> implement
 
   /** Open a writer appending to an existing file. */
   public DataFileWriter<D> appendTo(File file) throws IOException {
+    return appendTo(new SeekableFileInput(file),
+                    new FileOutputStream(file, true));
+  }
+
+  /** Open a writer appending to an existing file.
+   * @param in reading the existing file.
+   * @param out positioned at the end of the existing file.
+   */
+  public DataFileWriter<D> appendTo(SeekableInput in, OutputStream out)
+    throws IOException {
     assertNotOpen();
-    if (!file.exists())
-      throw new FileNotFoundException("Not found: "+file);
-    RandomAccessFile raf = new RandomAccessFile(file, "r");
-    FileDescriptor fd = raf.getFD();
     DataFileReader<D> reader =
-      new DataFileReader<D>(new SeekableFileInput(fd),
-                            new GenericDatumReader<D>());
+      new DataFileReader<D>(in, new GenericDatumReader<D>());
     this.schema = reader.getSchema();
     this.sync = reader.getHeader().sync;
     this.meta.putAll(reader.getHeader().meta);
@@ -167,9 +169,9 @@ public class DataFileWriter<D> implement
     } else {
       this.codec = CodecFactory.nullCodec().createInstance();
     }
-    raf.close();
+    reader.close();
 
-    init(new FileOutputStream(file, true));
+    init(out);
 
     return this;
   }



Mime
View raw message