Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 063291038A for ; Tue, 3 Dec 2013 06:06:04 +0000 (UTC) Received: (qmail 22439 invoked by uid 500); 3 Dec 2013 06:06:02 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 22365 invoked by uid 500); 3 Dec 2013 06:05:58 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 22357 invoked by uid 99); 3 Dec 2013 06:05:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Dec 2013 06:05:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Dec 2013 06:05:54 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id B915723888E2; Tue, 3 Dec 2013 06:05:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Tue, 03 Dec 2013 06:05:32 -0000 To: commits@hbase.apache.org From: apurtell@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131203060532.B915723888E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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); } }