Example usage for org.apache.hadoop.fs FSDataInputStream FSDataInputStream

List of usage examples for org.apache.hadoop.fs FSDataInputStream FSDataInputStream

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FSDataInputStream FSDataInputStream.

Prototype

public FSDataInputStream(InputStream in) 

Source Link

Usage

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testHeapPositionAndLimit() throws Exception {
    ByteBuffer readBuffer = ByteBuffer.allocate(20);
    readBuffer.position(5);//from w w w. j  a v  a2 s .  c  o  m
    readBuffer.limit(13);
    readBuffer.mark();

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream(7));

    int len = H1SeekableInputStream.readHeapBuffer(hadoopStream, readBuffer);
    Assert.assertEquals(7, len);
    Assert.assertEquals(12, readBuffer.position());
    Assert.assertEquals(13, readBuffer.limit());

    len = H1SeekableInputStream.readHeapBuffer(hadoopStream, readBuffer);
    Assert.assertEquals(1, len);
    Assert.assertEquals(13, readBuffer.position());
    Assert.assertEquals(13, readBuffer.limit());

    len = H1SeekableInputStream.readHeapBuffer(hadoopStream, readBuffer);
    Assert.assertEquals(0, len);

    readBuffer.reset();
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY, 0, 8), readBuffer);
}

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testDirectRead() throws Exception {
    ByteBuffer readBuffer = ByteBuffer.allocateDirect(20);

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream());

    int len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(10, len);//from  ww w .  j  ava 2 s. co  m
    Assert.assertEquals(10, readBuffer.position());
    Assert.assertEquals(20, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(-1, len);

    readBuffer.flip();
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY), readBuffer);
}

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testDirectSmallBuffer() throws Exception {
    ByteBuffer readBuffer = ByteBuffer.allocateDirect(5);

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream());

    int len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(5, len);//from   w ww. ja  v a2  s.c  o  m
    Assert.assertEquals(5, readBuffer.position());
    Assert.assertEquals(5, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(0, len);

    readBuffer.flip();
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY, 0, 5), readBuffer);
}

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testDirectSmallReads() throws Exception {
    ByteBuffer readBuffer = ByteBuffer.allocateDirect(10);

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream(2, 3, 3));

    int len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(2, len);//from  ww w .  ja v a2 s . c  o  m
    Assert.assertEquals(2, readBuffer.position());
    Assert.assertEquals(10, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(3, len);
    Assert.assertEquals(5, readBuffer.position());
    Assert.assertEquals(10, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(3, len);
    Assert.assertEquals(8, readBuffer.position());
    Assert.assertEquals(10, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(2, len);
    Assert.assertEquals(10, readBuffer.position());
    Assert.assertEquals(10, readBuffer.limit());

    readBuffer.flip();
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY), readBuffer);
}

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testDirectPosition() throws Exception {
    ByteBuffer readBuffer = ByteBuffer.allocateDirect(20);
    readBuffer.position(10);/* w  ww  .  j  av  a2 s  .  c  o m*/
    readBuffer.mark();

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream(8));

    int len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(8, len);
    Assert.assertEquals(18, readBuffer.position());
    Assert.assertEquals(20, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(2, len);
    Assert.assertEquals(20, readBuffer.position());
    Assert.assertEquals(20, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(-1, len);

    readBuffer.reset();
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY), readBuffer);
}

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testDirectLimit() throws Exception {
    ByteBuffer readBuffer = ByteBuffer.allocate(20);
    readBuffer.limit(8);/*from  w  w  w .  j  av a 2 s  . co  m*/

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream(7));

    int len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(7, len);
    Assert.assertEquals(7, readBuffer.position());
    Assert.assertEquals(8, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(1, len);
    Assert.assertEquals(8, readBuffer.position());
    Assert.assertEquals(8, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(0, len);

    readBuffer.flip();
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY, 0, 8), readBuffer);
}

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testDirectPositionAndLimit() throws Exception {
    ByteBuffer readBuffer = ByteBuffer.allocateDirect(20);
    readBuffer.position(5);//from w ww . ja  v  a2s. co  m
    readBuffer.limit(13);
    readBuffer.mark();

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream(7));

    int len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(7, len);
    Assert.assertEquals(12, readBuffer.position());
    Assert.assertEquals(13, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(1, len);
    Assert.assertEquals(13, readBuffer.position());
    Assert.assertEquals(13, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, TEMP.get());
    Assert.assertEquals(0, len);

    readBuffer.reset();
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY, 0, 8), readBuffer);
}

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testDirectSmallTempBufferSmallReads() throws Exception {
    byte[] temp = new byte[2]; // this will cause readDirectBuffer to loop

    ByteBuffer readBuffer = ByteBuffer.allocateDirect(10);

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream(2, 3, 3));

    int len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, temp);
    Assert.assertEquals(2, len);/*from  w  ww  .j  av a  2s  .co m*/
    Assert.assertEquals(2, readBuffer.position());
    Assert.assertEquals(10, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, temp);
    Assert.assertEquals(3, len);
    Assert.assertEquals(5, readBuffer.position());
    Assert.assertEquals(10, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, temp);
    Assert.assertEquals(3, len);
    Assert.assertEquals(8, readBuffer.position());
    Assert.assertEquals(10, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, temp);
    Assert.assertEquals(2, len);
    Assert.assertEquals(10, readBuffer.position());
    Assert.assertEquals(10, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, temp);
    Assert.assertEquals(-1, len);

    readBuffer.flip();
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY), readBuffer);
}

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testDirectSmallTempBufferWithPositionAndLimit() throws Exception {
    byte[] temp = new byte[2]; // this will cause readDirectBuffer to loop

    ByteBuffer readBuffer = ByteBuffer.allocateDirect(20);
    readBuffer.position(5);/*from   ww  w  . jav a 2  s .co  m*/
    readBuffer.limit(13);
    readBuffer.mark();

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream(7));

    int len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, temp);
    Assert.assertEquals(7, len);
    Assert.assertEquals(12, readBuffer.position());
    Assert.assertEquals(13, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, temp);
    Assert.assertEquals(1, len);
    Assert.assertEquals(13, readBuffer.position());
    Assert.assertEquals(13, readBuffer.limit());

    len = H1SeekableInputStream.readDirectBuffer(hadoopStream, readBuffer, temp);
    Assert.assertEquals(0, len);

    readBuffer.reset();
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY, 0, 8), readBuffer);
}

From source file:org.apache.parquet.hadoop.util.TestHadoop1ByteBufferReads.java

License:Apache License

@Test
public void testHeapReadFullySmallBuffer() throws Exception {
    ByteBuffer readBuffer = ByteBuffer.allocate(8);

    FSDataInputStream hadoopStream = new FSDataInputStream(new MockInputStream());

    H1SeekableInputStream.readFullyHeapBuffer(hadoopStream, readBuffer);
    Assert.assertEquals(8, readBuffer.position());
    Assert.assertEquals(8, readBuffer.limit());

    H1SeekableInputStream.readFullyHeapBuffer(hadoopStream, readBuffer);
    Assert.assertEquals(8, readBuffer.position());
    Assert.assertEquals(8, readBuffer.limit());

    readBuffer.flip();//from w  w  w  . ja  va  2  s.  c om
    Assert.assertEquals("Buffer contents should match", ByteBuffer.wrap(TEST_ARRAY, 0, 8), readBuffer);
}