Package org.apache.hadoop.io.simpleseekableformat

Examples of org.apache.hadoop.io.simpleseekableformat.SimpleSeekableFormatInputStream


    void read(final Random dataRandom2, final ByteArrayOutputStream inMemoryFile)
        throws Exception {

      // Open the in-memory file for read
      ByteArrayInputStream fileForRead = new ByteArrayInputStream(inMemoryFile.toByteArray());
      SimpleSeekableFormatInputStream in = new SimpleSeekableFormatInputStream(fileForRead);
      DataInputStream dataIn = new DataInputStream(in);

      // Verify the data
      for (int r = 0; r < numRecord; r++) {
        // Regenerate the same random bytes
        byte[] b = new byte[dataRandom2.nextInt(maxRecordSize)];
        UtilsForTests.nextBytes(dataRandom2, b, 16);
        // Read from the file
        byte[] b2 = new byte[b.length];
        dataIn.readFully(b2);
        UtilsForTests.assertArrayEquals("record " + r + " with length " + b.length,
            b, b2);
      }

      // Verify EOF
      Assert.assertEquals(-1, in.read());
      byte[] temp = new byte[100];
      Assert.assertEquals(-1, in.read(temp));
    }
View Full Code Here


            }
          }
        };
      }

      SimpleSeekableFormatInputStream in = new SimpleSeekableFormatInputStream(fileForRead);
      DataInputStream dataIn = new DataInputStream(in);

      long seekedPosition = in.seekForward();
      {
        // We should not be at the beginning of the stream any more.
        InterleavedInputStream interleavedIn = in.getInterleavedIn();
        long blocks = interleavedIn.getRawOffset() / interleavedIn.getCompleteBlockSize();
        long blocksAvailable = (availableBytes - interleavedIn.getMetaDataBlockSize()) / interleavedIn.getCompleteBlockSize();
        blocksAvailable = Math.max(0, blocksAvailable);
        Assert.assertTrue(blocks >= blocksAvailable);
      }

      long currentUncompressedPosition = 0;
      for (int r = 0; r < numRecord; r++) {
        // Regenerate the same random bytes
        byte[] b = new byte[dataRandom2.nextInt(maxRecordSize)];
        UtilsForTests.nextBytes(dataRandom2, b, 16);
        if (currentUncompressedPosition >= seekedPosition) {
          // Read from the file
          byte[] b2 = new byte[b.length];
          dataIn.readFully(b2);
          UtilsForTests.assertArrayEquals("record " + r + " with length " + b.length,
              b, b2);
        }
        currentUncompressedPosition += b.length;
      }

      // Verify EOF
      Assert.assertEquals(-1, in.read());
      byte[] temp = new byte[100];
      Assert.assertEquals(-1, in.read(temp));
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.io.simpleseekableformat.SimpleSeekableFormatInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.