org.apache.hadoop.io.IOUtils.wrappedReadForCompressedData()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中org.apache.hadoop.io.IOUtils.wrappedReadForCompressedData()方法的一些代码示例,展示了IOUtils.wrappedReadForCompressedData()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.wrappedReadForCompressedData()方法的具体详情如下:
包路径:org.apache.hadoop.io.IOUtils
类名称:IOUtils
方法名:wrappedReadForCompressedData

IOUtils.wrappedReadForCompressedData介绍

[英]Utility wrapper for reading from InputStream. It catches any errors thrown by the underlying stream (either IO or decompression-related), and re-throws as an IOException.
[中]用于从InputStream读取的实用程序包装器。它捕获底层流抛出的任何错误(IO或与解压缩相关),并作为IOException重新抛出。

代码示例

代码示例来源:origin: ch.cern.hadoop/hadoop-mapreduce-client-core

/**
 * Read upto len bytes into buf starting at offset off.
 * 
 * @param buf buffer 
 * @param off offset
 * @param len length of buffer
 * @return the no. of bytes read
 * @throws IOException
 */
private int readData(byte[] buf, int off, int len) throws IOException {
 int bytesRead = 0;
 while (bytesRead < len) {
  int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
    len - bytesRead);
  if (n < 0) {
   return bytesRead;
  }
  bytesRead += n;
 }
 return len;
}

代码示例来源:origin: io.hops/hadoop-mapreduce-client-core

/**
 * Read upto len bytes into buf starting at offset off.
 * 
 * @param buf buffer 
 * @param off offset
 * @param len length of buffer
 * @return the no. of bytes read
 * @throws IOException
 */
private int readData(byte[] buf, int off, int len) throws IOException {
 int bytesRead = 0;
 while (bytesRead < len) {
  int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
    len - bytesRead);
  if (n < 0) {
   return bytesRead;
  }
  bytesRead += n;
 }
 return len;
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-mapreduce-client-core

/**
 * Read upto len bytes into buf starting at offset off.
 * 
 * @param buf buffer 
 * @param off offset
 * @param len length of buffer
 * @return the no. of bytes read
 * @throws IOException
 */
private int readData(byte[] buf, int off, int len) throws IOException {
 int bytesRead = 0;
 while (bytesRead < len) {
  int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
    len - bytesRead);
  if (n < 0) {
   return bytesRead;
  }
  bytesRead += n;
 }
 return len;
}

代码示例来源:origin: org.apache.tez/tez-runtime-library

/**
 * Read up to len bytes into buf starting at offset off.
 *
 * @param buf buffer
 * @param off offset
 * @param len length of buffer
 * @return the no. of bytes read
 * @throws IOException
 */
private int readData(byte[] buf, int off, int len) throws IOException {
 int bytesRead = 0;
 while (bytesRead < len) {
  int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
    len - bytesRead);
  if (n < 0) {
   return bytesRead;
  }
  bytesRead += n;
 }
 return len;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Read upto len bytes into buf starting at offset off.
 * 
 * @param buf buffer 
 * @param off offset
 * @param len length of buffer
 * @return the no. of bytes read
 * @throws IOException
 */
private int readData(byte[] buf, int off, int len) throws IOException {
 int bytesRead = 0;
 while (bytesRead < len) {
  int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
    len - bytesRead);
  if (n < 0) {
   return bytesRead;
  }
  bytesRead += n;
 }
 return len;
}

代码示例来源:origin: ch.cern.hadoop/hadoop-common

@Test
public void testWrappedReadForCompressedData() throws IOException {
 byte[] buf = new byte[2];
 InputStream mockStream = Mockito.mock(InputStream.class);
 Mockito.when(mockStream.read(buf, 0, 1)).thenReturn(1);
 Mockito.when(mockStream.read(buf, 0, 2)).thenThrow(
   new java.lang.InternalError());
 try {
  assertEquals("Check expected value", 1,
    IOUtils.wrappedReadForCompressedData(mockStream, buf, 0, 1));
 } catch (IOException ioe) {
  fail("Unexpected error while reading");
 }
 try {
  IOUtils.wrappedReadForCompressedData(mockStream, buf, 0, 2);
 } catch (IOException ioe) {
  GenericTestUtils.assertExceptionContains(
    "Error while reading compressed data", ioe);
 }
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-common

@Test
public void testWrappedReadForCompressedData() throws IOException {
 byte[] buf = new byte[2];
 InputStream mockStream = Mockito.mock(InputStream.class);
 Mockito.when(mockStream.read(buf, 0, 1)).thenReturn(1);
 Mockito.when(mockStream.read(buf, 0, 2)).thenThrow(
   new java.lang.InternalError());
 try {
  assertEquals("Check expected value", 1,
    IOUtils.wrappedReadForCompressedData(mockStream, buf, 0, 1));
 } catch (IOException ioe) {
  fail("Unexpected error while reading");
 }
 try {
  IOUtils.wrappedReadForCompressedData(mockStream, buf, 0, 2);
 } catch (IOException ioe) {
  GenericTestUtils.assertExceptionContains(
    "Error while reading compressed data", ioe);
 }
}

相关文章