You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2013/12/03 07:05:32 UTC
svn commit: r1547294 - in /hbase/trunk:
hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/
Author: apurtell
Date: Tue Dec 3 06:05:32 2013
New Revision: 1547294
URL: http://svn.apache.org/r1547294
Log:
HBASE-10066. Use ByteArrayOutputStream#writeTo where appropriate
Modified:
hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterV3.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SecureWALCellCodec.java
Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java?rev=1547294&r1=1547293&r2=1547294&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java Tue Dec 3 06:05:32 2013
@@ -1752,9 +1752,9 @@ public final class ProtobufUtil {
public static byte [] toDelimitedByteArray(final Message m) throws IOException {
// Allocate arbitrary big size so we avoid resizing.
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+ baos.write(PB_MAGIC);
m.writeDelimitedTo(baos);
- baos.close();
- return ProtobufUtil.prependPBMagic(baos.toByteArray());
+ return baos.toByteArray();
}
/**
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java?rev=1547294&r1=1547293&r2=1547294&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java Tue Dec 3 06:05:32 2013
@@ -180,7 +180,7 @@ public class FixedFileTrailer {
// The last 4 bytes of the file encode the major and minor version universally
baosDos.writeInt(materializeVersion(majorVersion, minorVersion));
- outputStream.write(baos.toByteArray());
+ baos.writeTo(outputStream);
}
/**
@@ -208,8 +208,10 @@ public class FixedFileTrailer {
if (encryptionKey != null) {
builder.setEncryptionKey(ZeroCopyLiteralByteString.wrap(encryptionKey));
}
+ // We need this extra copy unfortunately to determine the final size of the
+ // delimited output, see use of baos.size() below.
builder.build().writeDelimitedTo(baos);
- output.write(baos.toByteArray());
+ baos.writeTo(output);
// Pad to make up the difference between variable PB encoding length and the
// length when encoded as writable under earlier V2 formats. Failure to pad
// properly or if the PB encoding is too big would mean the trailer wont be read
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterV3.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterV3.java?rev=1547294&r1=1547293&r2=1547294&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterV3.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileWriterV3.java Tue Dec 3 06:05:32 2013
@@ -17,7 +17,6 @@
*/
package org.apache.hadoop.hbase.io.hfile;
-import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -216,15 +215,11 @@ public class HFileWriterV3 extends HFile
if (cryptoContext != Encryption.Context.NONE) {
// Wrap the context's key and write it as the encryption metadata, the wrapper includes
// all information needed for decryption
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- os.write(EncryptionUtil.wrapKey(cryptoContext.getConf(),
+ trailer.setEncryptionKey(EncryptionUtil.wrapKey(cryptoContext.getConf(),
cryptoContext.getConf().get(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY,
User.getCurrent().getShortName()),
cryptoContext.getKey()));
- os.close();
- trailer.setEncryptionKey(os.toByteArray());
}
-
// Now we can finish the close
super.finishClose(trailer);
}
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SecureWALCellCodec.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SecureWALCellCodec.java?rev=1547294&r1=1547293&r2=1547294&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SecureWALCellCodec.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SecureWALCellCodec.java Tue Dec 3 06:05:32 2013
@@ -194,9 +194,8 @@ public class SecureWALCellCodec extends
cout.write(kvBuffer, pos, remainingLength);
cout.close();
- byte[] codedBytes = baos.toByteArray();
- StreamUtils.writeRawVInt32(out, codedBytes.length);
- out.write(codedBytes);
+ StreamUtils.writeRawVInt32(out, baos.size());
+ baos.writeTo(out);
}
}