0N/A/*
3261N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.io;
0N/A
0N/A/**
0N/A * Utility methods for packing/unpacking primitive values in/out of byte arrays
0N/A * using big-endian byte ordering.
0N/A */
0N/Aclass Bits {
0N/A
0N/A /*
0N/A * Methods for unpacking primitive values from byte arrays starting at
0N/A * given offsets.
0N/A */
0N/A
0N/A static boolean getBoolean(byte[] b, int off) {
0N/A return b[off] != 0;
0N/A }
0N/A
0N/A static char getChar(byte[] b, int off) {
2569N/A return (char) ((b[off + 1] & 0xFF) +
2569N/A (b[off] << 8));
0N/A }
0N/A
0N/A static short getShort(byte[] b, int off) {
2569N/A return (short) ((b[off + 1] & 0xFF) +
2569N/A (b[off] << 8));
0N/A }
0N/A
0N/A static int getInt(byte[] b, int off) {
2569N/A return ((b[off + 3] & 0xFF) ) +
2569N/A ((b[off + 2] & 0xFF) << 8) +
0N/A ((b[off + 1] & 0xFF) << 16) +
2569N/A ((b[off ] ) << 24);
0N/A }
0N/A
0N/A static float getFloat(byte[] b, int off) {
2569N/A return Float.intBitsToFloat(getInt(b, off));
0N/A }
0N/A
0N/A static long getLong(byte[] b, int off) {
2569N/A return ((b[off + 7] & 0xFFL) ) +
2569N/A ((b[off + 6] & 0xFFL) << 8) +
0N/A ((b[off + 5] & 0xFFL) << 16) +
0N/A ((b[off + 4] & 0xFFL) << 24) +
0N/A ((b[off + 3] & 0xFFL) << 32) +
0N/A ((b[off + 2] & 0xFFL) << 40) +
0N/A ((b[off + 1] & 0xFFL) << 48) +
2569N/A (((long) b[off]) << 56);
0N/A }
0N/A
0N/A static double getDouble(byte[] b, int off) {
2569N/A return Double.longBitsToDouble(getLong(b, off));
0N/A }
0N/A
0N/A /*
0N/A * Methods for packing primitive values into byte arrays starting at given
0N/A * offsets.
0N/A */
0N/A
0N/A static void putBoolean(byte[] b, int off, boolean val) {
0N/A b[off] = (byte) (val ? 1 : 0);
0N/A }
0N/A
0N/A static void putChar(byte[] b, int off, char val) {
2569N/A b[off + 1] = (byte) (val );
2569N/A b[off ] = (byte) (val >>> 8);
0N/A }
0N/A
0N/A static void putShort(byte[] b, int off, short val) {
2569N/A b[off + 1] = (byte) (val );
2569N/A b[off ] = (byte) (val >>> 8);
0N/A }
0N/A
0N/A static void putInt(byte[] b, int off, int val) {
2569N/A b[off + 3] = (byte) (val );
2569N/A b[off + 2] = (byte) (val >>> 8);
0N/A b[off + 1] = (byte) (val >>> 16);
2569N/A b[off ] = (byte) (val >>> 24);
0N/A }
0N/A
0N/A static void putFloat(byte[] b, int off, float val) {
2569N/A putInt(b, off, Float.floatToIntBits(val));
0N/A }
0N/A
0N/A static void putLong(byte[] b, int off, long val) {
2569N/A b[off + 7] = (byte) (val );
2569N/A b[off + 6] = (byte) (val >>> 8);
0N/A b[off + 5] = (byte) (val >>> 16);
0N/A b[off + 4] = (byte) (val >>> 24);
0N/A b[off + 3] = (byte) (val >>> 32);
0N/A b[off + 2] = (byte) (val >>> 40);
0N/A b[off + 1] = (byte) (val >>> 48);
2569N/A b[off ] = (byte) (val >>> 56);
0N/A }
0N/A
0N/A static void putDouble(byte[] b, int off, double val) {
2569N/A putLong(b, off, Double.doubleToLongBits(val));
0N/A }
0N/A}