avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From th...@apache.org
Subject svn commit: r1179387 - in /avro/trunk/lang/java/tools/src: main/java/org/apache/avro/tool/FromTextTool.java main/java/org/apache/avro/tool/Util.java test/java/org/apache/avro/tool/TestTextFileTools.java
Date Wed, 05 Oct 2011 19:06:08 GMT
Author: thiru
Date: Wed Oct  5 19:06:07 2011
New Revision: 1179387

URL: http://svn.apache.org/viewvc?rev=1179387&view=rev
Log:
AVRO-901 Java tools unit tests fail in Windows due to line termination and filenaming conventions

Modified:
    avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java
    avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
    avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java

Modified: avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java?rev=1179387&r1=1179386&r2=1179387&view=diff
==============================================================================
--- avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java (original)
+++ avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/FromTextTool.java Wed Oct
 5 19:06:07 2011
@@ -100,11 +100,14 @@ public class FromTextTool implements Too
       for (int i = 0; i < end; i++) {
         int b = buf[i] & 0xFF;
         if (b == '\n') {                          // newline
-          System.out.println("Writing line = "+line.position());
-          line.flip();
-          writer.append(line);
-          line.clear();
-          returnSeen = false;
+          if (!returnSeen) {
+            System.out.println("Writing line = "+line.position());
+            line.flip();
+            writer.append(line);
+            line.clear();
+          } else {
+            returnSeen = false;
+          }
         } else if (b == '\r') {                   // return
           line.flip();
           writer.append(line);

Modified: avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java?rev=1179387&r1=1179386&r2=1179387&view=diff
==============================================================================
--- avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java (original)
+++ avro/trunk/lang/java/tools/src/main/java/org/apache/avro/tool/Util.java Wed Oct  5 19:06:07
2011
@@ -21,7 +21,6 @@ import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -29,9 +28,9 @@ import java.io.OutputStream;
 import java.net.URI;
 
 import org.apache.avro.Schema;
+import org.apache.avro.file.DataFileReader;
 import org.apache.avro.generic.GenericDatumReader;
 import org.apache.avro.io.DecoderFactory;
-import org.apache.avro.file.DataFileReader;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -50,16 +49,12 @@ class Util {
     } 
     else {
       String[] parts = filename.split(":");
-      if (parts.length == 1) {
-        return new BufferedInputStream(new FileInputStream(new File(filename)));
-      }
-      else if (parts[0].equals("hdfs")) {
+      if (parts.length > 1 && parts[0].equals("hdfs")) {
         FileSystem fs = FileSystem.get(
             URI.create(filename), new Configuration());
         return new BufferedInputStream(fs.open(new Path(filename)));
-      }
-      else {
-        throw new FileNotFoundException();
+      } else {
+        return new BufferedInputStream(new FileInputStream(new File(filename)));
       }
     }
   }
@@ -76,17 +71,13 @@ class Util {
     } 
     else {
       String[] parts = filename.split(":");
-      if (parts.length == 1) {
-        return new BufferedOutputStream(
-            new FileOutputStream(new File(filename)));
-      }
-      else if (parts[0].equals("hdfs")) {
+      if (parts.length > 1 && parts[0].equals("hdfs")) {
         FileSystem fs = FileSystem.get(
-            URI.create(filename), new Configuration());
+          URI.create(filename), new Configuration());
         return new BufferedOutputStream(fs.create(new Path(filename)));
-      }
-      else {
-        throw new FileNotFoundException();
+      } else {
+        return new BufferedOutputStream(
+            new FileOutputStream(new File(filename)));
       }
     }
   }

Modified: avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java?rev=1179387&r1=1179386&r2=1179387&view=diff
==============================================================================
--- avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java (original)
+++ avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestTextFileTools.java Wed
Oct  5 19:06:07 2011
@@ -52,6 +52,7 @@ public class TestTextFileTools {
   private static final int COUNT =
     Integer.parseInt(System.getProperty("test.count", "10"));
 
+  private static final byte[] LINE_SEP = System.getProperty("line.separator").getBytes();
   static File linesFile;
   static ByteBuffer[] lines;
   static Schema schema;
@@ -76,7 +77,7 @@ public class TestTextFileTools {
         line[i] = (byte)b;
       }
       out.write(line);
-      out.write('\n');
+      out.write(LINE_SEP);
       lines[j] = ByteBuffer.wrap(line);
     }
     out.close();



Mime
View raw message