|
18 | 18 |
|
19 | 19 | package org.apache.hadoop.hbase.regionserver.wal; |
20 | 20 |
|
21 | | -import java.io.ByteArrayInputStream; |
22 | 21 | import java.io.ByteArrayOutputStream; |
23 | 22 | import java.io.IOException; |
24 | 23 | import java.io.InputStream; |
|
27 | 26 | import java.lang.reflect.InvocationTargetException; |
28 | 27 | import java.util.EnumMap; |
29 | 28 | import java.util.Map; |
30 | | -import org.apache.commons.io.IOUtils; |
31 | 29 | import org.apache.hadoop.conf.Configuration; |
32 | 30 | import org.apache.hadoop.hbase.HBaseInterfaceAudience; |
33 | | -import org.apache.hadoop.hbase.io.DelegatingInputStream; |
| 31 | +import org.apache.hadoop.hbase.io.BoundedDelegatingInputStream; |
34 | 32 | import org.apache.hadoop.hbase.io.TagCompressionContext; |
35 | 33 | import org.apache.hadoop.hbase.io.compress.Compression; |
36 | 34 | import org.apache.hadoop.hbase.io.util.Dictionary; |
@@ -71,7 +69,7 @@ static class ValueCompressor { |
71 | 69 | static final int IO_BUFFER_SIZE = 4096; |
72 | 70 |
|
73 | 71 | private final Compression.Algorithm algorithm; |
74 | | - private DelegatingInputStream lowerIn; |
| 72 | + private BoundedDelegatingInputStream lowerIn; |
75 | 73 | private ByteArrayOutputStream lowerOut; |
76 | 74 | private InputStream compressedIn; |
77 | 75 | private OutputStream compressedOut; |
@@ -102,31 +100,22 @@ public byte[] compress(byte[] valueArray, int valueOffset, int valueLength) |
102 | 100 | public int decompress(InputStream in, int inLength, byte[] outArray, int outOffset, |
103 | 101 | int outLength) throws IOException { |
104 | 102 |
|
105 | | - // We handle input as a sequence of byte[] arrays (call them segments), with |
106 | | - // DelegatingInputStream providing a way to switch in a new segment, wrapped in a |
107 | | - // ByteArrayInputStream, when the old segment has been fully consumed. |
108 | | - |
109 | | - // Originally I looked at using BoundedInputStream but you can't reuse/reset the |
110 | | - // BIS instance, and we can't just create new streams each time around because |
111 | | - // that would reset compression codec state, which must accumulate over all values |
112 | | - // in the file in order to build the dictionary in the same way as the compressor |
113 | | - // did. |
114 | | - |
115 | | - // Read in all of the next segment of compressed bytes to process. |
116 | | - byte[] inBuffer = new byte[inLength]; |
117 | | - IOUtils.readFully(in, inBuffer); |
| 103 | + // Our input is a sequence of bounded byte ranges (call them segments), with |
| 104 | + // BoundedDelegatingInputStream providing a way to switch in a new segment when the |
| 105 | + // previous segment has been fully consumed. |
118 | 106 |
|
119 | 107 | // Create the input streams here the first time around. |
120 | 108 | if (compressedIn == null) { |
121 | | - lowerIn = new DelegatingInputStream(new ByteArrayInputStream(inBuffer)); |
| 109 | + lowerIn = new BoundedDelegatingInputStream(in, inLength); |
122 | 110 | compressedIn = algorithm.createDecompressionStream(lowerIn, algorithm.getDecompressor(), |
123 | 111 | IO_BUFFER_SIZE); |
124 | 112 | } else { |
125 | | - lowerIn.setDelegate(new ByteArrayInputStream(inBuffer)); |
| 113 | + lowerIn.setDelegate(in, inLength); |
126 | 114 | } |
127 | 115 |
|
128 | | - // Caller must handle short reads. With current Hadoop compression codecs all 'outLength' |
129 | | - // bytes are read in here, so not an issue now. |
| 116 | + // Caller must handle short reads. |
| 117 | + // With current Hadoop compression codecs all 'outLength' bytes are read in here, so not |
| 118 | + // an issue for now. |
130 | 119 | return compressedIn.read(outArray, outOffset, outLength); |
131 | 120 | } |
132 | 121 |
|
|
0 commit comments