Skip to content

Commit df8e528

Browse files
committed
fixed line lengths and changed java test
1 parent 9a313d5 commit df8e528

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

core/src/main/scala/org/apache/spark/input/FixedLengthBinaryInputFormat.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ private[spark] object FixedLengthBinaryInputFormat {
4242

4343
}
4444

45-
private[spark] class FixedLengthBinaryInputFormat extends FileInputFormat[LongWritable, BytesWritable] {
45+
private[spark] class FixedLengthBinaryInputFormat
46+
extends FileInputFormat[LongWritable, BytesWritable] {
4647

4748

4849
/**

core/src/main/scala/org/apache/spark/input/FixedLengthBinaryRecordReader.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import org.apache.hadoop.mapreduce.lib.input.FileSplit
3737
* VALUE = the record itself (BytesWritable)
3838
*
3939
*/
40-
private[spark] class FixedLengthBinaryRecordReader extends RecordReader[LongWritable, BytesWritable] {
40+
private[spark] class FixedLengthBinaryRecordReader
41+
extends RecordReader[LongWritable, BytesWritable] {
4142

4243
override def close() {
4344
if (fileInputStream != null) {

core/src/test/java/org/apache/spark/JavaAPISuite.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package org.apache.spark;
1919

2020
import java.io.*;
21+
import java.nio.channels.FileChannel;
22+
import java.nio.ByteBuffer;
2123
import java.net.URI;
2224
import java.util.*;
2325

@@ -840,21 +842,22 @@ public Tuple2<Integer, String> call(Tuple2<IntWritable, Text> pair) {
840842
public void binaryFiles() throws Exception {
841843
// Reusing the wholeText files example
842844
byte[] content1 = "spark is easy to use.\n".getBytes("utf-8");
843-
byte[] content2 = "spark is also easy to use.\n".getBytes("utf-8");
845+
844846

845847
String tempDirName = tempDir.getAbsolutePath();
846848
File file1 = new File(tempDirName + "/part-00000");
847-
Files.write(content1, file1);
848-
File file2 = new File(tempDirName + "/part-00001");
849-
Files.write(content2, file2);
849+
850+
FileOutputStream fos1 = new FileOutputStream(file1);
851+
852+
FileChannel channel1 = fos1.getChannel();
853+
ByteBuffer bbuf = java.nio.ByteBuffer.wrap(content1);
854+
channel1.write(bbuf);
855+
850856

851857
JavaPairRDD<String, byte[]> readRDD = sc.binaryFiles(tempDirName,3);
852858
List<Tuple2<String, byte[]>> result = readRDD.collect();
853859
for (Tuple2<String, byte[]> res : result) {
854-
if (res._1()==file1.toString())
855-
Assert.assertArrayEquals(content1,res._2());
856-
else
857-
Assert.assertArrayEquals(content2,res._2());
860+
Assert.assertArrayEquals(content1, res._2());
858861
}
859862
}
860863

0 commit comments

Comments
 (0)