本文整理汇总了Java中org.apache.hadoop.io.compress.CompressionInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java CompressionInputStream.close方法的具体用法?Java CompressionInputStream.close怎么用?Java CompressionInputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.io.compress.CompressionInputStream
的用法示例。
在下文中一共展示了CompressionInputStream.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCompressAndDecompressConsistent
import org.apache.hadoop.io.compress.CompressionInputStream; //导入方法依赖的package包/类
@Test
public void testCompressAndDecompressConsistent() throws Exception {
final String testString = "Test String";
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final OutputStreamWriter writer = new OutputStreamWriter(subject.createOutputStream(baos));
writer.write(testString);
writer.flush();
writer.close();
final CompressionInputStream inputStream = subject.createInputStream(new ByteArrayInputStream(baos
.toByteArray()));
final StringWriter contentsTester = new StringWriter();
IOUtils.copy(inputStream, contentsTester);
inputStream.close();
contentsTester.flush();
contentsTester.close();
Assert.assertEquals(testString, contentsTester.toString());
}
示例2: testSnappyCompressionSimple
import org.apache.hadoop.io.compress.CompressionInputStream; //导入方法依赖的package包/类
@Test
public void testSnappyCompressionSimple() throws IOException
{
if (checkNativeSnappy()) {
return;
}
File snappyFile = new File(testMeta.getDir(), "snappyTestFile.snappy");
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(snappyFile));
Configuration conf = new Configuration();
CompressionCodec codec = (CompressionCodec)ReflectionUtils.newInstance(SnappyCodec.class, conf);
FilterStreamCodec.SnappyFilterStream filterStream = new FilterStreamCodec.SnappyFilterStream(
codec.createOutputStream(os));
int ONE_MB = 1024 * 1024;
String testStr = "TestSnap-16bytes";
for (int i = 0; i < ONE_MB; i++) { // write 16 MBs
filterStream.write(testStr.getBytes());
}
filterStream.flush();
filterStream.close();
CompressionInputStream is = codec.createInputStream(new FileInputStream(snappyFile));
byte[] recovered = new byte[testStr.length()];
int bytesRead = is.read(recovered);
is.close();
assertEquals(testStr, new String(recovered));
}
示例3: testStreamingFile
import org.apache.hadoop.io.compress.CompressionInputStream; //导入方法依赖的package包/类
@Test
public void testStreamingFile() throws Throwable {
// stream the data
FileLineStreamerImpl streamer = new FileLineStreamerImpl(codec,
new CompressionPoolFactoryImpl(10, 10, new AgentStatusImpl()));
ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream();
FileReader input = new FileReader(fileToStream);
BufferedReader reader = new BufferedReader(input);
FileLinePointer fileLinePointer = new FileLinePointer();
try {
boolean readLines = streamer.streamContent(fileLinePointer, reader,
bytesOutput);
assertTrue(readLines);
} finally {
reader.close();
}
System.out.println("Bytes Compressed: " + bytesOutput.size());
// validate that the data can be read again and all lines are available
ByteArrayInputStream bytesInput = new ByteArrayInputStream(
bytesOutput.toByteArray());
CompressionInputStream compressionInput = codec
.createInputStream(bytesInput);
BufferedReader buffReader = new BufferedReader(new InputStreamReader(
compressionInput));
StringBuilder buff = new StringBuilder();
try {
int lineCount = 0;
String line = null;
while ((line = buffReader.readLine()) != null) {
assertEquals(testString, line);
buff.append(line);
lineCount++;
}
System.out.println("String bytes: "
+ buff.toString().getBytes().length);
assertEquals(testLineCount, lineCount);
assertEquals(lineCount, fileLinePointer.getLineReadPointer());
} finally {
compressionInput.close();
buffReader.close();
}
}
示例4: checkSnappyFile
import org.apache.hadoop.io.compress.CompressionInputStream; //导入方法依赖的package包/类
private void checkSnappyFile(File file, List<Long> offsets, int startVal, int totalWindows, int totalRecords) throws IOException
{
FileInputStream fis;
InputStream gss = null;
Configuration conf = new Configuration();
CompressionCodec codec = (CompressionCodec)ReflectionUtils.newInstance(SnappyCodec.class, conf);
CompressionInputStream snappyIs = null;
BufferedReader br = null;
int numWindows = 0;
try {
fis = new FileInputStream(file);
gss = fis;
long startOffset = 0;
for (long offset : offsets) {
// Skip initial case in case file is not yet created
if (offset == 0) {
continue;
}
long limit = offset - startOffset;
LimitInputStream lis = new LimitInputStream(gss, limit);
snappyIs = codec.createInputStream(lis);
br = new BufferedReader(new InputStreamReader(snappyIs));
String eline = "" + (startVal + numWindows * 2);
int count = 0;
String line;
while ((line = br.readLine()) != null) {
Assert.assertEquals("File line", eline, line);
++count;
if ((count % totalRecords) == 0) {
++numWindows;
eline = "" + (startVal + numWindows * 2);
}
}
startOffset = offset;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (br != null) {
br.close();
} else {
if (snappyIs != null) {
snappyIs.close();
} else if (gss != null) {
gss.close();
}
}
}
Assert.assertEquals("Total", totalWindows, numWindows);
}