Return-Path: X-Original-To: apmail-hbase-issues-archive@www.apache.org Delivered-To: apmail-hbase-issues-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B0C5917CCB for ; Sat, 4 Apr 2015 07:04:33 +0000 (UTC) Received: (qmail 52251 invoked by uid 500); 4 Apr 2015 07:04:33 -0000 Delivered-To: apmail-hbase-issues-archive@hbase.apache.org Received: (qmail 52199 invoked by uid 500); 4 Apr 2015 07:04:33 -0000 Mailing-List: contact issues-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list issues@hbase.apache.org Received: (qmail 52186 invoked by uid 99); 4 Apr 2015 07:04:33 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Apr 2015 07:04:33 +0000 Date: Sat, 4 Apr 2015 07:04:33 +0000 (UTC) From: "Hudson (JIRA)" To: issues@hbase.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (HBASE-6919) Remove unnecessary throws IOException from Bytes.readVLong MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HBASE-6919?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14395597#comment-14395597 ] Hudson commented on HBASE-6919: ------------------------------- FAILURE: Integrated in HBase-0.98 #935 (See [https://builds.apache.org/job/HBase-0.98/935/]) HBASE-6919 Remove unnecessary throws IOException from Bytes.readVLong. (busbey: rev a734fdb60f36722aeca509c4c7e3c87a3569f6fc) * hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java * hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestBytes.java * hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV3.java * hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java > Remove unnecessary throws IOException from Bytes.readVLong > ---------------------------------------------------------- > > Key: HBASE-6919 > URL: https://issues.apache.org/jira/browse/HBASE-6919 > Project: HBase > Issue Type: Improvement > Reporter: James Taylor > Assignee: Apekshit Sharma > Priority: Minor > Labels: beginners > Fix For: 2.0.0, 1.1.0, 0.98.13 > > Attachments: HBASE-6919-v1.patch, HBASE-6919-v2.patch, HBASE-6919-v3.patch, HBASE-6919.patch > > > Remove the throws IOException so that caller doesn't have to catch and ignore. > {code} > public static long readVLong(final byte [] buffer, final int offset) > throws IOException > {code} > Also, add > {code} > public static int readVInt(final byte [] buffer, final int offset) > throws IOException { > return (int)readVLong(buffer,offset); > } > {code} > and these are useful too: > {code} > /** > * Put long as variable length encoded number at the offset in > * the result byte array. > * @param vint Integer to make a vint of. > * @param result buffer to put vint into > * @return Vint length in bytes of vint > */ > public static int vintToBytes(byte[] result, int offset, final long vint) { > long i = vint; > if (i >= -112 && i <= 127) { > result[offset] = (byte) i; > return 1; > } > int len = -112; > if (i < 0) { > i ^= -1L; // take one's complement' > len = -120; > } > long tmp = i; > while (tmp != 0) { > tmp = tmp >> 8; > len--; > } > result[offset++] = (byte) len; > len = (len < -120) ? -(len + 120) : -(len + 112); > for (int idx = len; idx != 0; idx--) { > int shiftbits = (idx - 1) * 8; > long mask = 0xFFL << shiftbits; > result[offset++] = (byte)((i & mask) >> shiftbits); > } > return len + 1; > } > /** > * Decode a vint from the buffer pointed at to by ptr and > * increment the offset of the ptr by the length of the > * vint. > * @param ptr a pointer to a byte array buffer > * @return the decoded vint value as an int > */ > public static int vintFromBytes(ImmutableBytesWritable ptr) { > return (int) vlongFromBytes(ptr); > } > > /** > * Decode a vint from the buffer pointed at to by ptr and > * increment the offset of the ptr by the length of the > * vint. > * @param ptr a pointer to a byte array buffer > * @return the decoded vint value as a long > */ > public static long vlongFromBytes(ImmutableBytesWritable ptr) { > final byte [] buffer = ptr.get(); > final int offset = ptr.getOffset(); > byte firstByte = buffer[offset]; > int len = WritableUtils.decodeVIntSize(firstByte); > if (len == 1) { > ptr.set(buffer, offset+1, ptr.getLength()); > return firstByte; > } > long i = 0; > for (int idx = 0; idx < len-1; idx++) { > byte b = buffer[offset + 1 + idx]; > i = i << 8; > i = i | (b & 0xFF); > } > ptr.set(buffer, offset+len, ptr.getLength()); > return (WritableUtils.isNegativeVInt(firstByte) ? ~i : i); > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)