类org.apache.hadoop.io.compress.lz4.Lz4Compressor源码实例Demo

下面列出了怎么用org.apache.hadoop.io.compress.lz4.Lz4Compressor的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop   文件: CompressDecompressTester.java
/**
 * Method for compressor availability check
 */
private static <T extends Compressor, E extends Decompressor> boolean isAvailable(TesterPair<T, E> pair) {
  Compressor compressor = pair.compressor;

  if (compressor.getClass().isAssignableFrom(Lz4Compressor.class)
          && (NativeCodeLoader.isNativeCodeLoaded()))
    return true;

  else if (compressor.getClass().isAssignableFrom(BuiltInZlibDeflater.class)
          && NativeCodeLoader.isNativeCodeLoaded())
    return true;

  else if (compressor.getClass().isAssignableFrom(ZlibCompressor.class)) {
    return ZlibFactory.isNativeZlibLoaded(new Configuration());
  }              
  else if (compressor.getClass().isAssignableFrom(SnappyCompressor.class)
          && isNativeSnappyLoadable())
    return true;
  
  return false;      
}
 
源代码2 项目: hadoop   文件: TestCompressorDecompressor.java
@Test
public void testCompressorDecompressor() {
  // no more for this data
  int SIZE = 44 * 1024;
  
  byte[] rawData = generate(SIZE);
  try {
    CompressDecompressTester.of(rawData)
        .withCompressDecompressPair(new SnappyCompressor(), new SnappyDecompressor())
        .withCompressDecompressPair(new Lz4Compressor(), new Lz4Decompressor())
        .withCompressDecompressPair(new BuiltInZlibDeflater(), new BuiltInZlibInflater())
        .withTestCases(ImmutableSet.of(CompressionTestStrategy.COMPRESS_DECOMPRESS_SINGLE_BLOCK,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_BLOCK,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_ERRORS,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_WITH_EMPTY_STREAM))
        .test();

  } catch (Exception ex) {
    fail("testCompressorDecompressor error !!!" + ex);
  }
}
 
源代码3 项目: hadoop   文件: TestCompressorDecompressor.java
@Test
public void testCompressorDecompressorWithExeedBufferLimit() {
  int BYTE_SIZE = 100 * 1024;
  byte[] rawData = generate(BYTE_SIZE);
  try {
    CompressDecompressTester.of(rawData)
        .withCompressDecompressPair(
            new SnappyCompressor(BYTE_SIZE + BYTE_SIZE / 2),
            new SnappyDecompressor(BYTE_SIZE + BYTE_SIZE / 2))
        .withCompressDecompressPair(new Lz4Compressor(BYTE_SIZE),
            new Lz4Decompressor(BYTE_SIZE))
        .withTestCases(ImmutableSet.of(CompressionTestStrategy.COMPRESS_DECOMPRESS_SINGLE_BLOCK,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_BLOCK,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_ERRORS,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_WITH_EMPTY_STREAM))
        .test();

  } catch (Exception ex) {
    fail("testCompressorDecompressorWithExeedBufferLimit error !!!" + ex);
  }
}
 
源代码4 项目: hadoop   文件: TestLz4CompressorDecompressor.java
@Test
public void testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize() {
  int BYTES_SIZE = 1024 * 64 + 1;
  try {
    Lz4Compressor compressor = new Lz4Compressor();
    byte[] bytes = generate(BYTES_SIZE);
    assertTrue("needsInput error !!!", compressor.needsInput());
    compressor.setInput(bytes, 0, bytes.length);
    byte[] emptyBytes = new byte[BYTES_SIZE];
    int csize = compressor.compress(emptyBytes, 0, bytes.length);
    assertTrue(
        "testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize error !!!",
        csize != 0);
  } catch (Exception ex) {
    fail("testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize ex error !!!");
  }
}
 
源代码5 项目: big-c   文件: CompressDecompressTester.java
/**
 * Method for compressor availability check
 */
private static <T extends Compressor, E extends Decompressor> boolean isAvailable(TesterPair<T, E> pair) {
  Compressor compressor = pair.compressor;

  if (compressor.getClass().isAssignableFrom(Lz4Compressor.class)
          && (NativeCodeLoader.isNativeCodeLoaded()))
    return true;

  else if (compressor.getClass().isAssignableFrom(BuiltInZlibDeflater.class)
          && NativeCodeLoader.isNativeCodeLoaded())
    return true;

  else if (compressor.getClass().isAssignableFrom(ZlibCompressor.class)) {
    return ZlibFactory.isNativeZlibLoaded(new Configuration());
  }              
  else if (compressor.getClass().isAssignableFrom(SnappyCompressor.class)
          && isNativeSnappyLoadable())
    return true;
  
  return false;      
}
 
源代码6 项目: big-c   文件: TestCompressorDecompressor.java
@Test
public void testCompressorDecompressor() {
  // no more for this data
  int SIZE = 44 * 1024;
  
  byte[] rawData = generate(SIZE);
  try {
    CompressDecompressTester.of(rawData)
        .withCompressDecompressPair(new SnappyCompressor(), new SnappyDecompressor())
        .withCompressDecompressPair(new Lz4Compressor(), new Lz4Decompressor())
        .withCompressDecompressPair(new BuiltInZlibDeflater(), new BuiltInZlibInflater())
        .withTestCases(ImmutableSet.of(CompressionTestStrategy.COMPRESS_DECOMPRESS_SINGLE_BLOCK,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_BLOCK,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_ERRORS,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_WITH_EMPTY_STREAM))
        .test();

  } catch (Exception ex) {
    fail("testCompressorDecompressor error !!!" + ex);
  }
}
 
源代码7 项目: big-c   文件: TestCompressorDecompressor.java
@Test
public void testCompressorDecompressorWithExeedBufferLimit() {
  int BYTE_SIZE = 100 * 1024;
  byte[] rawData = generate(BYTE_SIZE);
  try {
    CompressDecompressTester.of(rawData)
        .withCompressDecompressPair(
            new SnappyCompressor(BYTE_SIZE + BYTE_SIZE / 2),
            new SnappyDecompressor(BYTE_SIZE + BYTE_SIZE / 2))
        .withCompressDecompressPair(new Lz4Compressor(BYTE_SIZE),
            new Lz4Decompressor(BYTE_SIZE))
        .withTestCases(ImmutableSet.of(CompressionTestStrategy.COMPRESS_DECOMPRESS_SINGLE_BLOCK,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_BLOCK,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_ERRORS,
                    CompressionTestStrategy.COMPRESS_DECOMPRESS_WITH_EMPTY_STREAM))
        .test();

  } catch (Exception ex) {
    fail("testCompressorDecompressorWithExeedBufferLimit error !!!" + ex);
  }
}
 
源代码8 项目: big-c   文件: TestLz4CompressorDecompressor.java
@Test
public void testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize() {
  int BYTES_SIZE = 1024 * 64 + 1;
  try {
    Lz4Compressor compressor = new Lz4Compressor();
    byte[] bytes = generate(BYTES_SIZE);
    assertTrue("needsInput error !!!", compressor.needsInput());
    compressor.setInput(bytes, 0, bytes.length);
    byte[] emptyBytes = new byte[BYTES_SIZE];
    int csize = compressor.compress(emptyBytes, 0, bytes.length);
    assertTrue(
        "testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize error !!!",
        csize != 0);
  } catch (Exception ex) {
    fail("testSetInputWithBytesSizeMoreThenDefaultLz4CompressorByfferSize ex error !!!");
  }
}
 
源代码9 项目: hadoop   文件: Lz4Codec.java
/**
 * Get the type of {@link Compressor} needed by this {@link CompressionCodec}.
 *
 * @return the type of compressor needed by this codec.
 */
@Override
public Class<? extends Compressor> getCompressorType() {
  if (!isNativeCodeLoaded()) {
    throw new RuntimeException("native lz4 library not available");
  }

  return Lz4Compressor.class;
}
 
源代码10 项目: hadoop   文件: Lz4Codec.java
/**
 * Create a new {@link Compressor} for use by this {@link CompressionCodec}.
 *
 * @return a new compressor for use by this codec
 */
@Override
public Compressor createCompressor() {
  if (!isNativeCodeLoaded()) {
    throw new RuntimeException("native lz4 library not available");
  }
  int bufferSize = conf.getInt(
      CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZ4_BUFFERSIZE_KEY,
      CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZ4_BUFFERSIZE_DEFAULT);
  boolean useLz4HC = conf.getBoolean(
      CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZ4_USELZ4HC_KEY,
      CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZ4_USELZ4HC_DEFAULT);
  return new Lz4Compressor(bufferSize, useLz4HC);
}
 
源代码11 项目: hadoop   文件: TestLz4CompressorDecompressor.java
@Test
public void testCompressorSetInputNullPointerException() {
  try {
    Lz4Compressor compressor = new Lz4Compressor();
    compressor.setInput(null, 0, 10);
    fail("testCompressorSetInputNullPointerException error !!!");
  } catch (NullPointerException ex) {
    // expected
  } catch (Exception e) {
    fail("testCompressorSetInputNullPointerException ex error !!!");
  }
}
 
源代码12 项目: hadoop   文件: TestLz4CompressorDecompressor.java
@Test
public void testCompressorCompressNullPointerException() {
  try {
    Lz4Compressor compressor = new Lz4Compressor();
    byte[] bytes = generate(1024 * 6);
    compressor.setInput(bytes, 0, bytes.length);
    compressor.compress(null, 0, 0);
    fail("testCompressorCompressNullPointerException error !!!");
  } catch (NullPointerException ex) {
    // expected
  } catch (Exception e) {
    fail("testCompressorCompressNullPointerException ex error !!!");
  }
}
 
源代码13 项目: hadoop   文件: TestLz4CompressorDecompressor.java
@Test
public void testCompressorCompressAIOBException() {
  try {
    Lz4Compressor compressor = new Lz4Compressor();
    byte[] bytes = generate(1024 * 6);
    compressor.setInput(bytes, 0, bytes.length);
    compressor.compress(new byte[] {}, 0, -1);
    fail("testCompressorCompressAIOBException error !!!");
  } catch (ArrayIndexOutOfBoundsException ex) {
    // expected
  } catch (Exception e) {
    fail("testCompressorCompressAIOBException ex error !!!");
  }
}
 
源代码14 项目: hadoop   文件: TestLz4CompressorDecompressor.java
@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!!!");
  }
}
 
源代码15 项目: big-c   文件: Lz4Codec.java
/**
 * Get the type of {@link Compressor} needed by this {@link CompressionCodec}.
 *
 * @return the type of compressor needed by this codec.
 */
@Override
public Class<? extends Compressor> getCompressorType() {
  if (!isNativeCodeLoaded()) {
    throw new RuntimeException("native lz4 library not available");
  }

  return Lz4Compressor.class;
}
 
源代码16 项目: big-c   文件: Lz4Codec.java
/**
 * Create a new {@link Compressor} for use by this {@link CompressionCodec}.
 *
 * @return a new compressor for use by this codec
 */
@Override
public Compressor createCompressor() {
  if (!isNativeCodeLoaded()) {
    throw new RuntimeException("native lz4 library not available");
  }
  int bufferSize = conf.getInt(
      CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZ4_BUFFERSIZE_KEY,
      CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZ4_BUFFERSIZE_DEFAULT);
  boolean useLz4HC = conf.getBoolean(
      CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZ4_USELZ4HC_KEY,
      CommonConfigurationKeys.IO_COMPRESSION_CODEC_LZ4_USELZ4HC_DEFAULT);
  return new Lz4Compressor(bufferSize, useLz4HC);
}
 
源代码17 项目: big-c   文件: TestLz4CompressorDecompressor.java
@Test
public void testCompressorSetInputNullPointerException() {
  try {
    Lz4Compressor compressor = new Lz4Compressor();
    compressor.setInput(null, 0, 10);
    fail("testCompressorSetInputNullPointerException error !!!");
  } catch (NullPointerException ex) {
    // expected
  } catch (Exception e) {
    fail("testCompressorSetInputNullPointerException ex error !!!");
  }
}
 
源代码18 项目: big-c   文件: TestLz4CompressorDecompressor.java
@Test
public void testCompressorCompressNullPointerException() {
  try {
    Lz4Compressor compressor = new Lz4Compressor();
    byte[] bytes = generate(1024 * 6);
    compressor.setInput(bytes, 0, bytes.length);
    compressor.compress(null, 0, 0);
    fail("testCompressorCompressNullPointerException error !!!");
  } catch (NullPointerException ex) {
    // expected
  } catch (Exception e) {
    fail("testCompressorCompressNullPointerException ex error !!!");
  }
}
 
源代码19 项目: big-c   文件: TestLz4CompressorDecompressor.java
@Test
public void testCompressorCompressAIOBException() {
  try {
    Lz4Compressor compressor = new Lz4Compressor();
    byte[] bytes = generate(1024 * 6);
    compressor.setInput(bytes, 0, bytes.length);
    compressor.compress(new byte[] {}, 0, -1);
    fail("testCompressorCompressAIOBException error !!!");
  } catch (ArrayIndexOutOfBoundsException ex) {
    // expected
  } catch (Exception e) {
    fail("testCompressorCompressAIOBException ex error !!!");
  }
}
 
源代码20 项目: big-c   文件: TestLz4CompressorDecompressor.java
@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!!!");
  }
}
 
源代码21 项目: hadoop   文件: Lz4Codec.java
public static String getLibraryName() {
  return Lz4Compressor.getLibraryName();
}
 
源代码22 项目: big-c   文件: Lz4Codec.java
public static String getLibraryName() {
  return Lz4Compressor.getLibraryName();
}
 
源代码23 项目: datacollector   文件: Lz4Codec.java
public Lz4Codec() {
  super(Lz4Compressor.class, Lz4Decompressor.class, ".lz4");
}
 
源代码24 项目: datacollector   文件: Lz4Codec.java
@Override
public Compressor createCompressor() {
  return new Lz4Compressor(unsafe, getBufferSize(), useHC);
}
 
 类所在包
 同包方法