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

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

本文整理了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

  1. /**
  2. * Read upto len bytes into buf starting at offset off.
  3. *
  4. * @param buf buffer
  5. * @param off offset
  6. * @param len length of buffer
  7. * @return the no. of bytes read
  8. * @throws IOException
  9. */
  10. private int readData(byte[] buf, int off, int len) throws IOException {
  11. int bytesRead = 0;
  12. while (bytesRead < len) {
  13. int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
  14. len - bytesRead);
  15. if (n < 0) {
  16. return bytesRead;
  17. }
  18. bytesRead += n;
  19. }
  20. return len;
  21. }

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

  1. /**
  2. * Read upto len bytes into buf starting at offset off.
  3. *
  4. * @param buf buffer
  5. * @param off offset
  6. * @param len length of buffer
  7. * @return the no. of bytes read
  8. * @throws IOException
  9. */
  10. private int readData(byte[] buf, int off, int len) throws IOException {
  11. int bytesRead = 0;
  12. while (bytesRead < len) {
  13. int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
  14. len - bytesRead);
  15. if (n < 0) {
  16. return bytesRead;
  17. }
  18. bytesRead += n;
  19. }
  20. return len;
  21. }

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

  1. /**
  2. * Read upto len bytes into buf starting at offset off.
  3. *
  4. * @param buf buffer
  5. * @param off offset
  6. * @param len length of buffer
  7. * @return the no. of bytes read
  8. * @throws IOException
  9. */
  10. private int readData(byte[] buf, int off, int len) throws IOException {
  11. int bytesRead = 0;
  12. while (bytesRead < len) {
  13. int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
  14. len - bytesRead);
  15. if (n < 0) {
  16. return bytesRead;
  17. }
  18. bytesRead += n;
  19. }
  20. return len;
  21. }

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

  1. /**
  2. * Read up to len bytes into buf starting at offset off.
  3. *
  4. * @param buf buffer
  5. * @param off offset
  6. * @param len length of buffer
  7. * @return the no. of bytes read
  8. * @throws IOException
  9. */
  10. private int readData(byte[] buf, int off, int len) throws IOException {
  11. int bytesRead = 0;
  12. while (bytesRead < len) {
  13. int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
  14. len - bytesRead);
  15. if (n < 0) {
  16. return bytesRead;
  17. }
  18. bytesRead += n;
  19. }
  20. return len;
  21. }

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

  1. /**
  2. * Read upto len bytes into buf starting at offset off.
  3. *
  4. * @param buf buffer
  5. * @param off offset
  6. * @param len length of buffer
  7. * @return the no. of bytes read
  8. * @throws IOException
  9. */
  10. private int readData(byte[] buf, int off, int len) throws IOException {
  11. int bytesRead = 0;
  12. while (bytesRead < len) {
  13. int n = IOUtils.wrappedReadForCompressedData(in, buf, off + bytesRead,
  14. len - bytesRead);
  15. if (n < 0) {
  16. return bytesRead;
  17. }
  18. bytesRead += n;
  19. }
  20. return len;
  21. }

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

  1. @Test
  2. public void testWrappedReadForCompressedData() throws IOException {
  3. byte[] buf = new byte[2];
  4. InputStream mockStream = Mockito.mock(InputStream.class);
  5. Mockito.when(mockStream.read(buf, 0, 1)).thenReturn(1);
  6. Mockito.when(mockStream.read(buf, 0, 2)).thenThrow(
  7. new java.lang.InternalError());
  8. try {
  9. assertEquals("Check expected value", 1,
  10. IOUtils.wrappedReadForCompressedData(mockStream, buf, 0, 1));
  11. } catch (IOException ioe) {
  12. fail("Unexpected error while reading");
  13. }
  14. try {
  15. IOUtils.wrappedReadForCompressedData(mockStream, buf, 0, 2);
  16. } catch (IOException ioe) {
  17. GenericTestUtils.assertExceptionContains(
  18. "Error while reading compressed data", ioe);
  19. }
  20. }

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

  1. @Test
  2. public void testWrappedReadForCompressedData() throws IOException {
  3. byte[] buf = new byte[2];
  4. InputStream mockStream = Mockito.mock(InputStream.class);
  5. Mockito.when(mockStream.read(buf, 0, 1)).thenReturn(1);
  6. Mockito.when(mockStream.read(buf, 0, 2)).thenThrow(
  7. new java.lang.InternalError());
  8. try {
  9. assertEquals("Check expected value", 1,
  10. IOUtils.wrappedReadForCompressedData(mockStream, buf, 0, 1));
  11. } catch (IOException ioe) {
  12. fail("Unexpected error while reading");
  13. }
  14. try {
  15. IOUtils.wrappedReadForCompressedData(mockStream, buf, 0, 2);
  16. } catch (IOException ioe) {
  17. GenericTestUtils.assertExceptionContains(
  18. "Error while reading compressed data", ioe);
  19. }
  20. }

相关文章