Java Code Examples for org.apache.hadoop.io.compress.lz4.Lz4Decompressor#setInput()

The following examples show how to use org.apache.hadoop.io.compress.lz4.Lz4Decompressor#setInput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestLz4CompressorDecompressor.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecompressorSetInputNullPointerException() {
  try {
    Lz4Decompressor decompressor = new Lz4Decompressor();
    decompressor.setInput(null, 0, 10);
    fail("testDecompressorSetInputNullPointerException error !!!");
  } catch (NullPointerException ex) {
    // expected
  } catch (Exception e) {
    fail("testDecompressorSetInputNullPointerException ex error !!!");
  }
}
 
Example 2
Source File: TestLz4CompressorDecompressor.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecompressorSetInputAIOUBException() {
  try {
    Lz4Decompressor decompressor = new Lz4Decompressor();
    decompressor.setInput(new byte[] {}, -5, 10);
    fail("testDecompressorSetInputAIOBException error !!!");
  } catch (ArrayIndexOutOfBoundsException ex) {
    // expected
  } catch (Exception e) {
    fail("testDecompressorSetInputAIOBException ex error !!!");
  }
}
 
Example 3
Source File: TestLz4CompressorDecompressor.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecompressorCompressNullPointerException() {
  try {
    Lz4Decompressor decompressor = new Lz4Decompressor();
    byte[] bytes = generate(1024 * 6);
    decompressor.setInput(bytes, 0, bytes.length);
    decompressor.decompress(null, 0, 0);
    fail("testDecompressorCompressNullPointerException error !!!");
  } catch (NullPointerException ex) {
    // expected
  } catch (Exception e) {
    fail("testDecompressorCompressNullPointerException ex error !!!");
  }
}
 
Example 4
Source File: TestLz4CompressorDecompressor.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecompressorCompressAIOBException() {
  try {
    Lz4Decompressor decompressor = new Lz4Decompressor();
    byte[] bytes = generate(1024 * 6);
    decompressor.setInput(bytes, 0, bytes.length);
    decompressor.decompress(new byte[] {}, 0, -1);
    fail("testDecompressorCompressAIOBException error !!!");
  } catch (ArrayIndexOutOfBoundsException ex) {
    // expected
  } catch (Exception e) {
    fail("testDecompressorCompressAIOBException ex error !!!");
  }
}
 
Example 5
Source File: TestLz4CompressorDecompressor.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompressDecompress() {
  int BYTE_SIZE = 1024 * 54;
  byte[] bytes = generate(BYTE_SIZE);
  Lz4Compressor compressor = new Lz4Compressor();
  try {
    compressor.setInput(bytes, 0, bytes.length);
    assertTrue("Lz4CompressDecompress getBytesRead error !!!",
        compressor.getBytesRead() > 0);
    assertTrue(
        "Lz4CompressDecompress getBytesWritten before compress error !!!",
        compressor.getBytesWritten() == 0);

    byte[] compressed = new byte[BYTE_SIZE];
    int cSize = compressor.compress(compressed, 0, compressed.length);
    assertTrue(
        "Lz4CompressDecompress getBytesWritten after compress error !!!",
        compressor.getBytesWritten() > 0);
    Lz4Decompressor decompressor = new Lz4Decompressor();
    // set as input for decompressor only compressed data indicated with cSize
    decompressor.setInput(compressed, 0, cSize);
    byte[] decompressed = new byte[BYTE_SIZE];
    decompressor.decompress(decompressed, 0, decompressed.length);

    assertTrue("testLz4CompressDecompress finished error !!!", decompressor.finished());      
    assertArrayEquals(bytes, decompressed);
    compressor.reset();
    decompressor.reset();
    assertTrue("decompressor getRemaining error !!!",decompressor.getRemaining() == 0);
  } catch (Exception e) {
    fail("testLz4CompressDecompress ex error!!!");
  }
}
 
Example 6
Source File: TestLz4CompressorDecompressor.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecompressorSetInputNullPointerException() {
  try {
    Lz4Decompressor decompressor = new Lz4Decompressor();
    decompressor.setInput(null, 0, 10);
    fail("testDecompressorSetInputNullPointerException error !!!");
  } catch (NullPointerException ex) {
    // expected
  } catch (Exception e) {
    fail("testDecompressorSetInputNullPointerException ex error !!!");
  }
}
 
Example 7
Source File: TestLz4CompressorDecompressor.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecompressorSetInputAIOUBException() {
  try {
    Lz4Decompressor decompressor = new Lz4Decompressor();
    decompressor.setInput(new byte[] {}, -5, 10);
    fail("testDecompressorSetInputAIOBException error !!!");
  } catch (ArrayIndexOutOfBoundsException ex) {
    // expected
  } catch (Exception e) {
    fail("testDecompressorSetInputAIOBException ex error !!!");
  }
}
 
Example 8
Source File: TestLz4CompressorDecompressor.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecompressorCompressNullPointerException() {
  try {
    Lz4Decompressor decompressor = new Lz4Decompressor();
    byte[] bytes = generate(1024 * 6);
    decompressor.setInput(bytes, 0, bytes.length);
    decompressor.decompress(null, 0, 0);
    fail("testDecompressorCompressNullPointerException error !!!");
  } catch (NullPointerException ex) {
    // expected
  } catch (Exception e) {
    fail("testDecompressorCompressNullPointerException ex error !!!");
  }
}
 
Example 9
Source File: TestLz4CompressorDecompressor.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecompressorCompressAIOBException() {
  try {
    Lz4Decompressor decompressor = new Lz4Decompressor();
    byte[] bytes = generate(1024 * 6);
    decompressor.setInput(bytes, 0, bytes.length);
    decompressor.decompress(new byte[] {}, 0, -1);
    fail("testDecompressorCompressAIOBException error !!!");
  } catch (ArrayIndexOutOfBoundsException ex) {
    // expected
  } catch (Exception e) {
    fail("testDecompressorCompressAIOBException ex error !!!");
  }
}
 
Example 10
Source File: TestLz4CompressorDecompressor.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompressDecompress() {
  int BYTE_SIZE = 1024 * 54;
  byte[] bytes = generate(BYTE_SIZE);
  Lz4Compressor compressor = new Lz4Compressor();
  try {
    compressor.setInput(bytes, 0, bytes.length);
    assertTrue("Lz4CompressDecompress getBytesRead error !!!",
        compressor.getBytesRead() > 0);
    assertTrue(
        "Lz4CompressDecompress getBytesWritten before compress error !!!",
        compressor.getBytesWritten() == 0);

    byte[] compressed = new byte[BYTE_SIZE];
    int cSize = compressor.compress(compressed, 0, compressed.length);
    assertTrue(
        "Lz4CompressDecompress getBytesWritten after compress error !!!",
        compressor.getBytesWritten() > 0);
    Lz4Decompressor decompressor = new Lz4Decompressor();
    // set as input for decompressor only compressed data indicated with cSize
    decompressor.setInput(compressed, 0, cSize);
    byte[] decompressed = new byte[BYTE_SIZE];
    decompressor.decompress(decompressed, 0, decompressed.length);

    assertTrue("testLz4CompressDecompress finished error !!!", decompressor.finished());      
    assertArrayEquals(bytes, decompressed);
    compressor.reset();
    decompressor.reset();
    assertTrue("decompressor getRemaining error !!!",decompressor.getRemaining() == 0);
  } catch (Exception e) {
    fail("testLz4CompressDecompress ex error!!!");
  }
}