Browse files

Add asserts to check for null Configuration parameters in LzoCodec.

  • Loading branch information...
1 parent e710b83 commit 4537f94556c9ba71ffca316514e0c0101f76b63b @dvryaboy dvryaboy committed Jul 1, 2011
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/java/com/hadoop/compression/lzo/LzoCodec.java
View
21 src/java/com/hadoop/compression/lzo/LzoCodec.java
@@ -55,10 +55,12 @@
private Configuration conf;
+ @Override
public void setConf(Configuration conf) {
this.conf = conf;
}
+ @Override
public Configuration getConf() {
return conf;
}
@@ -88,6 +90,7 @@ public Configuration getConf() {
* else <code>false</code>
*/
public static boolean isNativeLzoLoaded(Configuration conf) {
+ assert conf != null : "Configuration cannot be null!";
return nativeLzoLoaded && conf.getBoolean("hadoop.native.lib", true);
}
@@ -102,10 +105,12 @@ public static String getRevisionHash() {
}
}
+ @Override
public CompressionOutputStream createOutputStream(OutputStream out) throws IOException {
return createOutputStream(out, createCompressor());
}
+ @Override
public CompressionOutputStream createOutputStream(OutputStream out,
Compressor compressor) throws IOException {
// Ensure native-lzo library is loaded & initialized
@@ -143,6 +148,7 @@ public CompressionOutputStream createOutputStream(OutputStream out,
compressionOverhead);
}
+ @Override
public Class<? extends Compressor> getCompressorType() {
// Ensure native-lzo library is loaded & initialized
if (!isNativeLzoLoaded(conf)) {
@@ -151,20 +157,24 @@ public CompressionOutputStream createOutputStream(OutputStream out,
return LzoCompressor.class;
}
+ @Override
public Compressor createCompressor() {
// Ensure native-lzo library is loaded & initialized
+ assert conf != null : "Configuration cannot be null! You must call setConf() before creating a compressor.";
if (!isNativeLzoLoaded(conf)) {
throw new RuntimeException("native-lzo library not available");
}
return new LzoCompressor(conf);
}
+ @Override
public CompressionInputStream createInputStream(InputStream in)
throws IOException {
return createInputStream(in, createDecompressor());
}
+ @Override
public CompressionInputStream createInputStream(InputStream in,
Decompressor decompressor)
throws IOException {
@@ -176,6 +186,7 @@ public CompressionInputStream createInputStream(InputStream in,
conf.getInt(LZO_BUFFER_SIZE_KEY, DEFAULT_LZO_BUFFER_SIZE));
}
+ @Override
public Class<? extends Decompressor> getDecompressorType() {
// Ensure native-lzo library is loaded & initialized
if (!isNativeLzoLoaded(conf)) {
@@ -184,6 +195,7 @@ public CompressionInputStream createInputStream(InputStream in,
return LzoDecompressor.class;
}
+ @Override
public Decompressor createDecompressor() {
// Ensure native-lzo library is loaded & initialized
if (!isNativeLzoLoaded(conf)) {
@@ -199,45 +211,54 @@ public Decompressor createDecompressor() {
* Get the default filename extension for this kind of compression.
* @return the extension including the '.'
*/
+ @Override
public String getDefaultExtension() {
return ".lzo_deflate";
}
static LzoCompressor.CompressionStrategy getCompressionStrategy(Configuration conf) {
+ assert conf != null : "Configuration cannot be null!";
return LzoCompressor.CompressionStrategy.valueOf(
conf.get(LZO_COMPRESSOR_KEY,
LzoCompressor.CompressionStrategy.LZO1X_1.name()));
}
static LzoDecompressor.CompressionStrategy getDecompressionStrategy(Configuration conf) {
+ assert conf != null : "Configuration cannot be null!";
return LzoDecompressor.CompressionStrategy.valueOf(
conf.get(LZO_DECOMPRESSOR_KEY,
LzoDecompressor.CompressionStrategy.LZO1X.name()));
}
static int getCompressionLevel(Configuration conf) {
+ assert conf != null : "Configuration cannot be null!";
return conf.getInt(LZO_COMPRESSION_LEVEL_KEY, UNDEFINED_COMPRESSION_LEVEL);
}
static int getBufferSize(Configuration conf) {
+ assert conf != null : "Configuration cannot be null!";
return conf.getInt(LZO_BUFFER_SIZE_KEY, DEFAULT_LZO_BUFFER_SIZE);
}
public static void setCompressionStrategy(Configuration conf,
LzoCompressor.CompressionStrategy strategy) {
+ assert conf != null : "Configuration cannot be null!";
conf.set(LZO_COMPRESSOR_KEY, strategy.name());
}
public static void setDecompressionStrategy(Configuration conf,
LzoDecompressor.CompressionStrategy strategy) {
+ assert conf != null : "Configuration cannot be null!";
conf.set(LZO_DECOMPRESSOR_KEY, strategy.name());
}
public static void setCompressionLevel(Configuration conf, int compressionLevel) {
+ assert conf != null : "Configuration cannot be null!";
conf.setInt(LZO_COMPRESSION_LEVEL_KEY, compressionLevel);
}
public static void setBufferSize(Configuration conf, int bufferSize) {
+ assert conf != null : "Configuration cannot be null!";
conf.setInt(LZO_BUFFER_SIZE_KEY, bufferSize);
}

0 comments on commit 4537f94

Please sign in to comment.