You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2011/10/27 10:22:49 UTC
svn commit: r1189662 - in /commons/proper/compress/trunk/src:
main/java/org/apache/commons/compress/archivers/dump/
test/java/org/apache/commons/compress/archivers/dump/
Author: bodewig
Date: Thu Oct 27 08:22:48 2011
New Revision: 1189662
URL: http://svn.apache.org/viewvc?rev=1189662&view=rev
Log:
remove unneeded cast to int in bitwise operations, add tests for convert methods
Added:
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java (with props)
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtil.java
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtil.java?rev=1189662&r1=1189661&r2=1189662&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtil.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtil.java Thu Oct 27 08:22:48 2011
@@ -108,10 +108,10 @@ class DumpArchiveUtil {
*/
public static final int convert32(byte[] buffer, int offset) {
int i = 0;
- i = ((int) buffer[offset + 3]) << 24;
- i += (((int) buffer[offset + 2] << 16) & 0x00FF0000);
- i += (((int) buffer[offset + 1] << 8) & 0x0000FF00);
- i += (((int) buffer[offset]) & 0x000000FF);
+ i = buffer[offset + 3] << 24;
+ i += (buffer[offset + 2] << 16) & 0x00FF0000;
+ i += (buffer[offset + 1] << 8) & 0x0000FF00;
+ i += buffer[offset] & 0x000000FF;
return i;
}
@@ -125,8 +125,8 @@ class DumpArchiveUtil {
*/
public static final int convert16(byte[] buffer, int offset) {
int i = 0;
- i += (((int) buffer[offset + 1] << 8) & 0x0000FF00);
- i += (((int) buffer[offset]) & 0x000000FF);
+ i += (buffer[offset + 1] << 8) & 0x0000FF00;
+ i += buffer[offset] & 0x000000FF;
return i;
}
Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java?rev=1189662&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java (added)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java Thu Oct 27 08:22:48 2011
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress.archivers.dump;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class DumpArchiveUtilTest {
+
+ @Test
+ public void convert64() {
+ assertEquals(0xABCDEF0123456780L,
+ DumpArchiveUtil.convert64(new byte[] {
+ (byte) 0x80, 0x67, 0x45, 0x23, 1, (byte) 0xEF,
+ (byte) 0xCD, (byte) 0xAB
+ }, 0));
+ }
+
+ @Test
+ public void convert32() {
+ assertEquals(0xABCDEF01,
+ DumpArchiveUtil.convert32(new byte[] {
+ 1, (byte) 0xEF, (byte) 0xCD, (byte) 0xAB
+ }, 0));
+ }
+
+ @Test
+ public void convert16() {
+ assertEquals(0xABCD,
+ DumpArchiveUtil.convert16(new byte[] {
+ (byte) 0xCD, (byte) 0xAB
+ }, 0));
+ }
+}
\ No newline at end of file
Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native