當前位置: 首頁>>代碼示例>>Java>>正文


Java CompressionInputStream.close方法代碼示例

本文整理匯總了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());
}
 
開發者ID:Conductor,項目名稱:kangaroo,代碼行數:20,代碼來源:SnappyFramedCodecTest.java

示例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));
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:32,代碼來源:AbstractFileOutputOperatorTest.java

示例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();
	}

}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:57,代碼來源:TestFileLineStreamerImpl.java

示例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);
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:55,代碼來源:AbstractFileOutputOperatorTest.java


注:本文中的org.apache.hadoop.io.compress.CompressionInputStream.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。