本文整理汇总了Java中org.apache.hadoop.io.compress.SnappyCodec.isNativeCodeLoaded方法的典型用法代码示例。如果您正苦于以下问题:Java SnappyCodec.isNativeCodeLoaded方法的具体用法?Java SnappyCodec.isNativeCodeLoaded怎么用?Java SnappyCodec.isNativeCodeLoaded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.io.compress.SnappyCodec
的用法示例。
在下文中一共展示了SnappyCodec.isNativeCodeLoaded方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isHadoopSnappyAvailable
import org.apache.hadoop.io.compress.SnappyCodec; //导入方法依赖的package包/类
/**
* Tests whether hadoop-snappy (not to be confused with other java-based snappy implementations such as jsnappy or
* snappy-java) plus the native snappy libraries are available.
*
* @return true if hadoop-snappy is available on the classpath
*/
public boolean isHadoopSnappyAvailable() {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
try {
return SnappyCodec.isNativeCodeLoaded();
} catch ( Throwable t ) {
return false;
} finally {
Thread.currentThread().setContextClassLoader( cl );
}
}
示例2: open
import org.apache.hadoop.io.compress.SnappyCodec; //导入方法依赖的package包/类
@Override
public void open() {
Preconditions.checkState(state.equals(ReaderWriterState.NEW),
"Unable to open a writer from state:%s", state);
logger.debug(
"Opening data file with pathTmp:{} (final path will be path:{})",
pathTmp, path);
try {
CompressionCodecName codecName = CompressionCodecName.UNCOMPRESSED;
if (enableCompression) {
if (SnappyCodec.isNativeCodeLoaded()) {
codecName = CompressionCodecName.SNAPPY;
} else {
logger.warn("Compression enabled, but Snappy native code not loaded. " +
"Parquet file will not be compressed.");
}
}
avroParquetWriter = new AvroParquetWriter<E>(fileSystem.makeQualified(pathTmp),
schema, codecName, DEFAULT_BLOCK_SIZE,
ParquetWriter.DEFAULT_PAGE_SIZE);
} catch (IOException e) {
throw new DatasetWriterException("Unable to create writer to path:" + pathTmp, e);
}
state = ReaderWriterState.OPEN;
}
示例3: main
import org.apache.hadoop.io.compress.SnappyCodec; //导入方法依赖的package包/类
/**
* A tool to test native library availability,
*/
public static void main(String[] args) {
String usage = "NativeLibraryChecker [-a|-h]\n"
+ " -a use -a to check all libraries are available\n"
+ " by default just check hadoop library is available\n"
+ " exit with error code 1 if check failed\n"
+ " -h print this message\n";
if (args.length > 1 ||
(args.length == 1 &&
!(args[0].equals("-a") || args[0].equals("-h")))) {
System.err.println(usage);
ExitUtil.terminate(1);
}
boolean checkAll = false;
if (args.length == 1) {
if (args[0].equals("-h")) {
System.out.println(usage);
return;
}
checkAll = true;
}
Configuration conf = new Configuration();
boolean nativeHadoopLoaded = NativeCodeLoader.isNativeCodeLoaded();
boolean zlibLoaded = false;
boolean snappyLoaded = false;
// lz4 is linked within libhadoop
boolean lz4Loaded = nativeHadoopLoaded;
boolean bzip2Loaded = Bzip2Factory.isNativeBzip2Loaded(conf);
String hadoopLibraryName = "";
String zlibLibraryName = "";
String snappyLibraryName = "";
String lz4LibraryName = "";
String bzip2LibraryName = "";
if (nativeHadoopLoaded) {
hadoopLibraryName = NativeCodeLoader.getLibraryName();
zlibLoaded = ZlibFactory.isNativeZlibLoaded(conf);
if (zlibLoaded) {
zlibLibraryName = ZlibFactory.getLibraryName();
}
snappyLoaded = NativeCodeLoader.buildSupportsSnappy() &&
SnappyCodec.isNativeCodeLoaded();
if (snappyLoaded && NativeCodeLoader.buildSupportsSnappy()) {
snappyLibraryName = SnappyCodec.getLibraryName();
}
if (lz4Loaded) {
lz4LibraryName = Lz4Codec.getLibraryName();
}
if (bzip2Loaded) {
bzip2LibraryName = Bzip2Factory.getLibraryName(conf);
}
}
System.out.println("Native library checking:");
System.out.printf("hadoop: %b %s\n", nativeHadoopLoaded, hadoopLibraryName);
System.out.printf("zlib: %b %s\n", zlibLoaded, zlibLibraryName);
System.out.printf("snappy: %b %s\n", snappyLoaded, snappyLibraryName);
System.out.printf("lz4: %b %s\n", lz4Loaded, lz4LibraryName);
System.out.printf("bzip2: %b %s\n", bzip2Loaded, bzip2LibraryName);
if ((!nativeHadoopLoaded) ||
(checkAll && !(zlibLoaded && snappyLoaded && lz4Loaded && bzip2Loaded))) {
// return 1 to indicated check failed
ExitUtil.terminate(1);
}
}