-/*\r
- * Licensed to the Apache Software Foundation (ASF) under one or more\r
- * contributor license agreements. See the NOTICE file distributed with\r
- * this work for additional information regarding copyright ownership.\r
- * The ASF licenses this file to You under the Apache License, Version 2.0\r
- * (the "License"); you may not use this file except in compliance with\r
- * the License. You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- *\r
- */\r
-\r
-package org.apache.tools.zip;\r
-\r
-/**\r
- * Utility class that represents a two byte integer with conversion\r
- * rules for the big endian byte order of ZIP files.\r
- *\r
- */\r
-public final class ZipShort implements Cloneable {\r
- private static final int BYTE_MASK = 0xFF;\r
- private static final int BYTE_1_MASK = 0xFF00;\r
- private static final int BYTE_1_SHIFT = 8;\r
-\r
- private int value;\r
-\r
- /**\r
- * Create instance from a number.\r
- * @param value the int to store as a ZipShort\r
- * @since 1.1\r
- */\r
- public ZipShort (int value) {\r
- this.value = value;\r
- }\r
-\r
- /**\r
- * Create instance from bytes.\r
- * @param bytes the bytes to store as a ZipShort\r
- * @since 1.1\r
- */\r
- public ZipShort (byte[] bytes) {\r
- this(bytes, 0);\r
- }\r
-\r
- /**\r
- * Create instance from the two bytes starting at offset.\r
- * @param bytes the bytes to store as a ZipShort\r
- * @param offset the offset to start\r
- * @since 1.1\r
- */\r
- public ZipShort (byte[] bytes, int offset) {\r
- value = ZipShort.getValue(bytes, offset);\r
- }\r
-\r
- /**\r
- * Get value as two bytes in big endian byte order.\r
- * @return the value as a a two byte array in big endian byte order\r
- * @since 1.1\r
- */\r
- public byte[] getBytes() {\r
- byte[] result = new byte[2];\r
- result[0] = (byte) (value & BYTE_MASK);\r
- result[1] = (byte) ((value & BYTE_1_MASK) >> BYTE_1_SHIFT);\r
- return result;\r
- }\r
-\r
- /**\r
- * Get value as Java int.\r
- * @return value as a Java int\r
- * @since 1.1\r
- */\r
- public int getValue() {\r
- return value;\r
- }\r
-\r
- /**\r
- * Get value as two bytes in big endian byte order.\r
- * @param value the Java int to convert to bytes\r
- * @return the converted int as a byte array in big endian byte order\r
- */\r
- public static byte[] getBytes(int value) {\r
- byte[] result = new byte[2];\r
- result[0] = (byte) (value & BYTE_MASK);\r
- result[1] = (byte) ((value & BYTE_1_MASK) >> BYTE_1_SHIFT);\r
- return result;\r
- }\r
-\r
- /**\r
- * Helper method to get the value as a java int from two bytes starting at given array offset\r
- * @param bytes the array of bytes\r
- * @param offset the offset to start\r
- * @return the correspondanding java int value\r
- */\r
- public static int getValue(byte[] bytes, int offset) {\r
- int value = (bytes[offset + 1] << BYTE_1_SHIFT) & BYTE_1_MASK;\r
- value += (bytes[offset] & BYTE_MASK);\r
- return value;\r
- }\r
-\r
- /**\r
- * Helper method to get the value as a java int from a two-byte array\r
- * @param bytes the array of bytes\r
- * @return the correspondanding java int value\r
- */\r
- public static int getValue(byte[] bytes) {\r
- return getValue(bytes, 0);\r
- }\r
-\r
- /**\r
- * Override to make two instances with same value equal.\r
- * @param o an object to compare\r
- * @return true if the objects are equal\r
- * @since 1.1\r
- */\r
- public boolean equals(Object o) {\r
- if (o == null || !(o instanceof ZipShort)) {\r
- return false;\r
- }\r
- return value == ((ZipShort) o).getValue();\r
- }\r
-\r
- /**\r
- * Override to make two instances with same value equal.\r
- * @return the value stored in the ZipShort\r
- * @since 1.1\r
- */\r
- public int hashCode() {\r
- return value;\r
- }\r
-\r
- public Object clone() {\r
- try {\r
- return super.clone();\r
- } catch (CloneNotSupportedException cnfe) {\r
- // impossible\r
- throw new RuntimeException(cnfe);\r
- }\r
- }\r
-}\r
+/*
+ * 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.tools.zip;
+
+/**
+ * Utility class that represents a two byte integer with conversion
+ * rules for the big endian byte order of ZIP files.
+ *
+ */
+public final class ZipShort implements Cloneable {
+ private static final int BYTE_MASK = 0xFF;
+ private static final int BYTE_1_MASK = 0xFF00;
+ private static final int BYTE_1_SHIFT = 8;
+
+ private int value;
+
+ /**
+ * Create instance from a number.
+ * @param value the int to store as a ZipShort
+ * @since 1.1
+ */
+ public ZipShort (int value) {
+ this.value = value;
+ }
+
+ /**
+ * Create instance from bytes.
+ * @param bytes the bytes to store as a ZipShort
+ * @since 1.1
+ */
+ public ZipShort (byte[] bytes) {
+ this(bytes, 0);
+ }
+
+ /**
+ * Create instance from the two bytes starting at offset.
+ * @param bytes the bytes to store as a ZipShort
+ * @param offset the offset to start
+ * @since 1.1
+ */
+ public ZipShort (byte[] bytes, int offset) {
+ value = ZipShort.getValue(bytes, offset);
+ }
+
+ /**
+ * Get value as two bytes in big endian byte order.
+ * @return the value as a a two byte array in big endian byte order
+ * @since 1.1
+ */
+ public byte[] getBytes() {
+ byte[] result = new byte[2];
+ result[0] = (byte) (value & BYTE_MASK);
+ result[1] = (byte) ((value & BYTE_1_MASK) >> BYTE_1_SHIFT);
+ return result;
+ }
+
+ /**
+ * Get value as Java int.
+ * @return value as a Java int
+ * @since 1.1
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Get value as two bytes in big endian byte order.
+ * @param value the Java int to convert to bytes
+ * @return the converted int as a byte array in big endian byte order
+ */
+ public static byte[] getBytes(int value) {
+ byte[] result = new byte[2];
+ result[0] = (byte) (value & BYTE_MASK);
+ result[1] = (byte) ((value & BYTE_1_MASK) >> BYTE_1_SHIFT);
+ return result;
+ }
+
+ /**
+ * Helper method to get the value as a java int from two bytes starting at given array offset
+ * @param bytes the array of bytes
+ * @param offset the offset to start
+ * @return the correspondanding java int value
+ */
+ public static int getValue(byte[] bytes, int offset) {
+ int value = (bytes[offset + 1] << BYTE_1_SHIFT) & BYTE_1_MASK;
+ value += (bytes[offset] & BYTE_MASK);
+ return value;
+ }
+
+ /**
+ * Helper method to get the value as a java int from a two-byte array
+ * @param bytes the array of bytes
+ * @return the correspondanding java int value
+ */
+ public static int getValue(byte[] bytes) {
+ return getValue(bytes, 0);
+ }
+
+ /**
+ * Override to make two instances with same value equal.
+ * @param o an object to compare
+ * @return true if the objects are equal
+ * @since 1.1
+ */
+ public boolean equals(Object o) {
+ if (o == null || !(o instanceof ZipShort)) {
+ return false;
+ }
+ return value == ((ZipShort) o).getValue();
+ }
+
+ /**
+ * Override to make two instances with same value equal.
+ * @return the value stored in the ZipShort
+ * @since 1.1
+ */
+ public int hashCode() {
+ return value;
+ }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException cnfe) {
+ // impossible
+ throw new RuntimeException(cnfe);
+ }
+ }
+}