@Test public void read_large() throws Exception { Path path = new Path("large"); LongWritable key = new LongWritable(); LongWritable value = new LongWritable(); try (SequenceFile.Writer writer = SequenceFile.createWriter(conf, SequenceFile.Writer.file(fs.makeQualified(path)), SequenceFile.Writer.keyClass(key.getClass()), SequenceFile.Writer.valueClass(value.getClass()))) { for (long i = 0; i < 300000; i++) { key.set(i); value.set(i + 1); writer.append(key, value); } } FileStatus status = fs.getFileStatus(path); try (InputStream in = new FileInputStream(fs.pathToFile(path)); SequenceFile.Reader reader = SequenceFileUtil.openReader(in, status, conf)) { for (long i = 0; i < 300000; i++) { assertThat(reader.next(key, value), is(true)); assertThat(key.get(), is(i)); assertThat(value.get(), is(i + 1)); } assertThat(reader.next(key, value), is(false)); } }
public static SequenceFile.Reader openReader( InputStream in, FileStatus status, Configuration conf) throws IOException { if (in == null) { throw new IllegalArgumentException("in must not be null"); } if (status == null) { throw new IllegalArgumentException("status must not be null"); } if (conf == null) { throw new IllegalArgumentException("conf must not be null"); } if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format( "Creating sequence file reader for {0}", status.getPath())); } return new SequenceFile.Reader( conf, SequenceFile.Reader.stream(new FSDataInputStream(new WrappedInputStream(in))), SequenceFile.Reader.length(status.getLen())); }
SequenceFileUtil { public static SequenceFile.Reader openReader( InputStream in, FileStatus status, Configuration conf) throws IOException { if (in == null) { throw new IllegalArgumentException("in must not be null"); } if (status == null) { throw new IllegalArgumentException("status must not be null"); } if (conf == null) { throw new IllegalArgumentException("conf must not be null"); } if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format( "Creating sequence file reader for {0}", status.getPath())); } return new SequenceFile.Reader( conf, SequenceFile.Reader.stream(new FSDataInputStream(new WrappedInputStream(in))), SequenceFile.Reader.length(status.getLen())); } }
SequenceFileUtil { public static SequenceFile.Reader openReader( InputStream in, FileStatus status, Configuration conf) throws IOException { if (in == null) { throw new IllegalArgumentException("in must not be null"); } if (status == null) { throw new IllegalArgumentException("status must not be null"); } if (conf == null) { throw new IllegalArgumentException("conf must not be null"); } if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format( "Creating sequence file reader for {0}", status.getPath())); } return new SequenceFile.Reader( conf, SequenceFile.Reader.stream(new FSDataInputStream(new WrappedInputStream(in))), SequenceFile.Reader.length(status.getLen())); } private  SequenceFileUtil(); }
SequenceFileUtil { public static SequenceFile.Reader openReader( InputStream in, FileStatus status, Configuration conf) throws IOException { if (in == null) { throw new IllegalArgumentException("in must not be null"); } if (status == null) { throw new IllegalArgumentException("status must not be null"); } if (conf == null) { throw new IllegalArgumentException("conf must not be null"); } if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format( "Creating sequence file reader for {0}", status.getPath())); } return new SequenceFile.Reader( conf, SequenceFile.Reader.stream(new FSDataInputStream(new WrappedInputStream(in))), SequenceFile.Reader.length(status.getLen())); } private  SequenceFileUtil(); static SequenceFile.Reader openReader(
            InputStream in,
            FileStatus status,
            Configuration conf); static SequenceFile.Reader openReader(
            InputStream in,
            long length,
            Configuration conf); static SequenceFile.Writer openWriter(
            OutputStream out, Configuration conf,
            Class<?> keyClass, Class<?> valueClass,
            CompressionCodec codec); }
SequenceFileUtil { public static SequenceFile.Reader openReader( InputStream in, FileStatus status, Configuration conf) throws IOException { if (in == null) { throw new IllegalArgumentException("in must not be null"); } if (status == null) { throw new IllegalArgumentException("status must not be null"); } if (conf == null) { throw new IllegalArgumentException("conf must not be null"); } if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format( "Creating sequence file reader for {0}", status.getPath())); } return new SequenceFile.Reader( conf, SequenceFile.Reader.stream(new FSDataInputStream(new WrappedInputStream(in))), SequenceFile.Reader.length(status.getLen())); } private  SequenceFileUtil(); static SequenceFile.Reader openReader(
            InputStream in,
            FileStatus status,
            Configuration conf); static SequenceFile.Reader openReader(
            InputStream in,
            long length,
            Configuration conf); static SequenceFile.Writer openWriter(
            OutputStream out, Configuration conf,
            Class<?> keyClass, Class<?> valueClass,
            CompressionCodec codec);  }