Example usage for java.nio ByteOrder BIG_ENDIAN

List of usage examples for java.nio ByteOrder BIG_ENDIAN

Introduction

In this page you can find the example usage for java.nio ByteOrder BIG_ENDIAN.

Prototype

ByteOrder BIG_ENDIAN

To view the source code for java.nio ByteOrder BIG_ENDIAN.

Click Source Link

Document

This constant represents big endian.

Usage

From source file:com.inductiveautomation.xopc.drivers.modbus2.requests.WriteSingleRegisterRequest.java

private short getRegisterValue(ModbusAddress address, Variant variant) {
    ModbusDataType modbusType = address.getModbusDataType();

    switch (modbusType) {
    case BCD16:/* w w  w .  j  a va  2  s  . c om*/
        short bcd16 = (Short) TypeUtilities.coerce(variant.getValue(), Short.class);
        byte[] bcdBytes = BCDByteUtilities.get(ByteOrder.BIG_ENDIAN).fromShort(bcd16, 0xFFFF);

        return ByteUtilities.get(ByteOrder.BIG_ENDIAN).getShort(bcdBytes, 0);

    case String:
        // This is copypasta from WriteMultipleRegistersRequest... yuck.
        String s = TypeUtilities.toString(variant.getValue());
        int addressLength = address.getStringLength();

        if (s.length() > addressLength) {
            s = s.substring(0, addressLength);
        }

        byte[] padding = new byte[addressLength - s.length()];
        Arrays.fill(padding, (byte) ' ');

        byte[] stringBytes = rightJustifyStrings ? ArrayUtils.addAll(padding, s.getBytes())
                : ArrayUtils.addAll(s.getBytes(), padding);

        if (reverseStringByteOrder) {
            byte[] reversed = new byte[stringBytes.length];
            for (int i = 0; i < stringBytes.length; i += 2) {
                byte[] swapped = ByteUtilities.swapBytes(stringBytes, i);
                System.arraycopy(swapped, 0, reversed, i, swapped.length);
            }
            stringBytes = reversed;
        }

        return ByteUtilities.get(ByteOrder.BIG_ENDIAN).getShort(stringBytes, 0);

    default:
        return (Short) TypeUtilities.coerce(variant.getValue(), Short.class);
    }
}

From source file:org.openhab.binding.modbus.internal.ModbusBinding.java

private DecimalType extractStateFromRegisters(InputRegister[] registers, int index, String type) {
    if (type.equals(ModbusBindingProvider.VALUE_TYPE_BIT)) {
        return new DecimalType((registers[index / 16].toUnsignedShort() >> (index % 16)) & 1);
    } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_INT8)) {
        return new DecimalType(registers[index / 2].toBytes()[1 - (index % 2)]);
    } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_UINT8)) {
        return new DecimalType((registers[index / 2].toUnsignedShort() >> (8 * (index % 2))) & 0xff);
    } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_INT16)) {
        ByteBuffer buff = ByteBuffer.allocate(2);
        buff.put(registers[index].toBytes());
        return new DecimalType(buff.order(ByteOrder.BIG_ENDIAN).getShort(0));
    } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_UINT16)) {
        return new DecimalType(registers[index].toUnsignedShort());
    } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_INT32)) {
        ByteBuffer buff = ByteBuffer.allocate(4);
        buff.put(registers[index * 2 + 0].toBytes());
        buff.put(registers[index * 2 + 1].toBytes());
        return new DecimalType(buff.order(ByteOrder.BIG_ENDIAN).getInt(0));
    } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_UINT32)) {
        ByteBuffer buff = ByteBuffer.allocate(8);
        buff.position(4);/*  w  w w  . j a  v  a2s  .  c o  m*/
        buff.put(registers[index * 2 + 0].toBytes());
        buff.put(registers[index * 2 + 1].toBytes());
        return new DecimalType(buff.order(ByteOrder.BIG_ENDIAN).getLong(0));
    } else if (type.equals(ModbusBindingProvider.VALUE_TYPE_FLOAT32)) {
        ByteBuffer buff = ByteBuffer.allocate(4);
        buff.put(registers[index * 2 + 0].toBytes());
        buff.put(registers[index * 2 + 1].toBytes());
        return new DecimalType(buff.order(ByteOrder.BIG_ENDIAN).getFloat(0));
    } else {
        throw new IllegalArgumentException();
    }
}

From source file:org.xenei.compressedgraph.SerializableNode.java

public static byte[] getRawIdx(int i) {
    byte[] retval = new byte[4];
    ByteBuffer.wrap(retval).order(ByteOrder.BIG_ENDIAN).putInt(i);
    return retval;
}

From source file:ffx.xray.MTZFilter.java

/**
 * {@inheritDoc}//from w  ww .  j a v  a2 s . co  m
 */
@Override
public ReflectionList getReflectionList(File mtzFile, CompositeConfiguration properties) {
    ByteOrder b = ByteOrder.nativeOrder();
    FileInputStream fis;
    DataInputStream dis;
    try {
        fis = new FileInputStream(mtzFile);
        dis = new DataInputStream(fis);

        byte headeroffset[] = new byte[4];
        byte bytes[] = new byte[80];
        int offset = 0;

        // eat "MTZ" title
        dis.read(bytes, offset, 4);
        String mtzstr = new String(bytes);

        // header offset
        dis.read(headeroffset, offset, 4);

        // machine stamp
        dis.read(bytes, offset, 4);
        ByteBuffer bb = ByteBuffer.wrap(bytes);
        int stamp = bb.order(ByteOrder.BIG_ENDIAN).getInt();
        String stampstr = Integer.toHexString(stamp);
        switch (stampstr.charAt(0)) {
        case '1':
        case '3':
            if (b.equals(ByteOrder.LITTLE_ENDIAN)) {
                b = ByteOrder.BIG_ENDIAN;
            }
            break;
        case '4':
            if (b.equals(ByteOrder.BIG_ENDIAN)) {
                b = ByteOrder.LITTLE_ENDIAN;
            }
            break;
        }

        bb = ByteBuffer.wrap(headeroffset);
        int headeroffseti = bb.order(b).getInt();

        // skip to header and parse
        dis.skipBytes((headeroffseti - 4) * 4);

        for (Boolean parsing = true; parsing; dis.read(bytes, offset, 80)) {
            mtzstr = new String(bytes);
            parsing = parseHeader(mtzstr);
        }
    } catch (EOFException eof) {
        System.out.println("EOF reached ");
    } catch (IOException ioe) {
        System.out.println("IO Exception: " + ioe.getMessage());
        return null;
    }

    // column identifiers
    foString = sigfoString = rfreeString = null;
    if (properties != null) {
        foString = properties.getString("fostring", null);
        sigfoString = properties.getString("sigfostring", null);
        rfreeString = properties.getString("rfreestring", null);
    }
    h = k = l = fo = sigfo = rfree = -1;
    fplus = sigfplus = fminus = sigfminus = rfreeplus = rfreeminus = -1;
    fc = phic = -1;
    boolean print = false;
    parseColumns(print);
    parseFcColumns(print);

    if (fo < 0 && fplus < 0 && sigfo < 0 && sigfplus < 0 && fc < 0 && phic < 0) {
        logger.info(
                " The MTZ header contains insufficient information to generate the reflection list.\n For non-default column labels set fostring/sigfostring in the properties file.");
        return null;
    }

    Column c;
    if (fo > 0) {
        c = (Column) columns.get(fo);
    } else if (fplus > 0) {
        c = (Column) columns.get(fplus);
    } else {
        c = (Column) columns.get(fc);
    }
    Dataset d = (Dataset) datasets.get(c.id - dsetoffset);

    if (logger.isLoggable(Level.INFO)) {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\n Reading %s\n\n", mtzFile.getName()));
        sb.append(String.format(" Setting up reflection list based on MTZ file.\n"));
        sb.append(String.format(" Space group number: %d (name: %s)\n", sgnum,
                SpaceGroup.spaceGroupNames[sgnum - 1]));
        sb.append(String.format(" Resolution: %8.3f\n", 0.999999 * resHigh));
        sb.append(String.format(" Cell: %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", d.cell[0], d.cell[1], d.cell[2],
                d.cell[3], d.cell[4], d.cell[5]));
        logger.info(sb.toString());
    }

    Crystal crystal = new Crystal(d.cell[0], d.cell[1], d.cell[2], d.cell[3], d.cell[4], d.cell[5],
            SpaceGroup.spaceGroupNames[sgnum - 1]);

    double sampling = 0.6;
    if (properties != null) {
        sampling = properties.getDouble("sampling", 0.6);
    }
    Resolution resolution = new Resolution(0.999999 * resHigh, sampling);

    return new ReflectionList(crystal, resolution, properties);
}

From source file:org.openspaces.memcached.protocol.binary.MemcachedBinaryResponseEncoder.java

@Override
public void messageReceived(ChannelHandlerContext channelHandlerContext, MessageEvent messageEvent)
        throws Exception {
    ResponseMessage command = (ResponseMessage) messageEvent.getMessage();
    Object additional = messageEvent.getMessage();

    MemcachedBinaryCommandDecoder.BinaryOp bcmd = MemcachedBinaryCommandDecoder.BinaryOp
            .forCommandMessage(command.cmd);

    // write extras == flags & expiry
    ChannelBuffer extrasBuffer = null;//from ww w  .  j av a 2 s.  co  m

    // write key if there is one
    ChannelBuffer keyBuffer = null;
    if (bcmd.isAddKeyToResponse() && command.cmd.keys != null && command.cmd.keys.size() != 0) {
        keyBuffer = ChannelBuffers.wrappedBuffer(command.cmd.keys.get(0).bytes);
    }

    // write value if there is one
    ChannelBuffer valueBuffer = null;
    if (command.elements != null) {
        extrasBuffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, 4);
        LocalCacheElement element = command.elements[0];
        extrasBuffer.writeShort((short) (element != null ? element.getExpire() : 0));
        extrasBuffer.writeShort((short) (element != null ? element.getFlags() : 0));

        if ((command.cmd.op == Op.GET || command.cmd.op == Op.GETS)) {
            if (element != null) {
                valueBuffer = ChannelBuffers.wrappedBuffer(ByteOrder.BIG_ENDIAN, element.getData());
            } else {
                valueBuffer = ChannelBuffers.buffer(0);
            }
        } else if (command.cmd.op == Op.INCR || command.cmd.op == Op.DECR) {
            valueBuffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, 8);
            valueBuffer.writeLong(command.incrDecrResponse);
        }
    } else if (command.cmd.op == Op.INCR || command.cmd.op == Op.DECR) {
        valueBuffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, 8);
        valueBuffer.writeLong(command.incrDecrResponse);
    }

    long casUnique = 0;
    if (command.elements != null && command.elements.length != 0 && command.elements[0] != null) {
        casUnique = command.elements[0].getCasUnique();
    }

    // stats is special -- with it, we write N times, one for each stat, then an empty payload
    if (command.cmd.op == Op.STATS) {
        // first uncork any corked buffers
        if (corkedBuffers.containsKey(command.cmd.opaque))
            uncork(command.cmd.opaque, messageEvent.getChannel());

        for (Map.Entry<String, Set<String>> statsEntries : command.stats.entrySet()) {
            for (String stat : statsEntries.getValue()) {

                // Move to use this in Java 6
                //                    keyBuffer = ChannelBuffers.wrappedBuffer(ByteOrder.BIG_ENDIAN, statsEntries.getKey().getBytes(MemcachedBinaryCommandDecoder.USASCII.toString()));
                //                    valueBuffer = ChannelBuffers.wrappedBuffer(ByteOrder.BIG_ENDIAN, stat.getBytes(MemcachedBinaryCommandDecoder.USASCII));

                keyBuffer = ChannelBuffers.wrappedBuffer(ByteOrder.BIG_ENDIAN,
                        statsEntries.getKey().getBytes("US-ASCII"));
                valueBuffer = ChannelBuffers.wrappedBuffer(ByteOrder.BIG_ENDIAN, stat.getBytes("US-ASCII"));

                ChannelBuffer headerBuffer = constructHeader(bcmd, extrasBuffer, keyBuffer, valueBuffer,
                        getStatusCode(command).code, command.cmd.opaque, casUnique);

                writePayload(messageEvent, extrasBuffer, keyBuffer, valueBuffer, headerBuffer);
            }
        }

        keyBuffer = null;
        valueBuffer = null;

        ChannelBuffer headerBuffer = constructHeader(bcmd, extrasBuffer, keyBuffer, valueBuffer,
                getStatusCode(command).code, command.cmd.opaque, casUnique);

        writePayload(messageEvent, extrasBuffer, keyBuffer, valueBuffer, headerBuffer);

    } else {
        ChannelBuffer headerBuffer = constructHeader(bcmd, extrasBuffer, keyBuffer, valueBuffer,
                getStatusCode(command).code, command.cmd.opaque, casUnique);

        // write everything
        // is the command 'quiet?' if so, then we append to our 'corked' buffer until a non-corked command comes along
        if (bcmd.isNoreply()) {
            int totalCapacity = headerBuffer.capacity() + (extrasBuffer != null ? extrasBuffer.capacity() : 0)
                    + (keyBuffer != null ? keyBuffer.capacity() : 0)
                    + (valueBuffer != null ? valueBuffer.capacity() : 0);

            ChannelBuffer corkedResponse = cork(command.cmd.opaque, totalCapacity);

            corkedResponse.writeBytes(headerBuffer);
            if (extrasBuffer != null)
                corkedResponse.writeBytes(extrasBuffer);
            if (keyBuffer != null)
                corkedResponse.writeBytes(keyBuffer);
            if (valueBuffer != null)
                corkedResponse.writeBytes(valueBuffer);
        } else {
            // first write out any corked responses
            if (corkedBuffers.containsKey(command.cmd.opaque))
                uncork(command.cmd.opaque, messageEvent.getChannel());

            writePayload(messageEvent, extrasBuffer, keyBuffer, valueBuffer, headerBuffer);
        }
    }
}

From source file:com.inductiveautomation.xopc.drivers.modbus2.requests.WriteMultipleRegistersRequest.java

private byte[] getValue(WriteItem item, ModbusAddress address) {
    ModbusDataType modbusType = address.getModbusDataType();
    Variant variant = item.getWriteValue();

    switch (modbusType) {
    case BCD16://from  w  w  w.j a v a 2  s .  com
        short bcd16 = (Short) TypeUtilities.coerce(variant.getValue(), Short.class);
        return BCDByteUtilities.get(ByteOrder.BIG_ENDIAN).fromShort(bcd16, 0xFFFF);

    case BCD32:
        int bcd32 = (Integer) TypeUtilities.coerce(variant.getValue(), Integer.class);
        byte[] bcd32bs = BCDByteUtilities.get(ByteOrder.BIG_ENDIAN).fromInt(bcd32, 0xFFFFFFFF);
        if (swapWords) {
            return ByteUtilities.swapWords(bcd32bs, 0);
        }
        return bcd32bs;

    case Int16:
    case UInt16:
        return UAByteUtilities.fromVariant(variant, ByteOrder.BIG_ENDIAN);

    case Int32:
    case UInt32:
    case Float:
        byte[] bs = UAByteUtilities.fromVariant(variant, ByteOrder.BIG_ENDIAN);
        if (swapWords) {
            return ByteUtilities.swapWords(bs, 0);
        }
        return bs;

    case Int64:
    case UInt64:
    case Double:
        byte[] bs64 = UAByteUtilities.fromVariant(variant, ByteOrder.BIG_ENDIAN);
        if (swapWords) {
            byte[] h1 = ByteUtilities.swapWords(bs64, 0);
            byte[] h2 = ByteUtilities.swapWords(bs64, 4);
            System.arraycopy(h2, 0, bs64, 0, 4);
            System.arraycopy(h1, 0, bs64, 4, 4);
        }
        return bs64;

    case String:
        String s = TypeUtilities.toString(variant.getValue());
        int addressLength = address.getStringLength();

        if (s.length() > addressLength) {
            s = s.substring(0, addressLength);
        }

        byte[] padding = new byte[addressLength - s.length()];
        Arrays.fill(padding, (byte) ' ');

        byte[] stringBytes = rightJustifyStrings ? ArrayUtils.addAll(padding, s.getBytes())
                : ArrayUtils.addAll(s.getBytes(), padding);

        if (reverseStringByteOrder) {
            byte[] reversed = new byte[stringBytes.length];
            for (int i = 0; i < stringBytes.length; i += 2) {
                byte[] swapped = ByteUtilities.swapBytes(stringBytes, i);
                System.arraycopy(swapped, 0, reversed, i, swapped.length);
            }
            stringBytes = reversed;
        }

        return stringBytes;

    case Boolean:
        throw new RuntimeException(String.format("Writing %s to %s not allowed.", modbusType, address));

    default:
        throw new RuntimeException(String.format("Case for %s not defined.", modbusType));
    }
}

From source file:ome.io.bioformats.BfPyramidPixelBuffer.java

private synchronized void initializeReader() throws IOException, FormatException {
    if (isLockedByOthers()) {
        throw new LockTimeout(String.format("%s is locked by others", readerFile.getAbsolutePath()), 15 * 1000,
                0);/*from   w w  w.j a v  a 2  s. c o  m*/
    }
    reader = new OmeroPixelsPyramidReader();
    delegate = new BfPixelBuffer(readerFile.getAbsolutePath(), reader);
    byteOrder = delegate.isLittleEndian() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
}

From source file:ffx.xray.CCP4MapFilter.java

/**
 * {@inheritDoc}/*from ww w  .j av a2s .  c  om*/
 */
@Override
public boolean readFile(String filename, RealSpaceRefinementData refinementdata,
        CompositeConfiguration properties) {

    int imapdata;
    double cella, cellb, cellc, cellalpha, cellbeta, cellgamma;
    String stampstr;

    ByteOrder b = ByteOrder.nativeOrder();

    FileInputStream fis;
    DataInputStream dis;

    double min = Double.POSITIVE_INFINITY;
    double max = Double.NEGATIVE_INFINITY;
    double mean = 0.0;
    double sd = 0.0;
    double rmsd = 0.0;

    // first determine byte order of file versus system
    try {
        fis = new FileInputStream(filename);
        dis = new DataInputStream(fis);

        dis.skipBytes(212);
        byte bytes[] = new byte[4];
        dis.read(bytes, 0, 4);
        ByteBuffer bb = ByteBuffer.wrap(bytes);

        imapdata = bb.order(ByteOrder.BIG_ENDIAN).getInt();
        stampstr = Integer.toHexString(imapdata);
        // System.out.println("stamp: " + stampstr);
        switch (stampstr.charAt(0)) {
        case '1':
        case '3':
            if (b.equals(ByteOrder.LITTLE_ENDIAN)) {
                b = ByteOrder.BIG_ENDIAN;
            }
            break;
        case '4':
            if (b.equals(ByteOrder.BIG_ENDIAN)) {
                b = ByteOrder.LITTLE_ENDIAN;
            }
            break;
        }

        if (logger.isLoggable(Level.INFO)) {
            StringBuilder sb = new StringBuilder();
            sb.append(String.format("\nOpening CCP4 map: %s\n", filename));
            sb.append(String.format("file type (machine stamp): %s\n", stampstr));
            logger.info(sb.toString());
        }

        fis.close();
    } catch (Exception e) {
        String message = "Fatal exception reading CCP4 map.\n";
        logger.log(Level.SEVERE, message, e);
        System.exit(-1);
    }

    try {
        fis = new FileInputStream(filename);
        dis = new DataInputStream(fis);

        byte bytes[] = new byte[2048];

        dis.read(bytes, 0, 1024);
        ByteBuffer bb = ByteBuffer.wrap(bytes);

        int ext[] = new int[3];
        ext[0] = bb.order(b).getInt();
        ext[1] = bb.order(b).getInt();
        ext[2] = bb.order(b).getInt();

        // mode (2 = reals, only one we accept)
        int mode = bb.order(b).getInt();

        int ori[] = new int[3];
        ori[0] = bb.order(b).getInt();
        ori[1] = bb.order(b).getInt();
        ori[2] = bb.order(b).getInt();

        int ni[] = new int[3];
        ni[0] = bb.order(b).getInt();
        ni[1] = bb.order(b).getInt();
        ni[2] = bb.order(b).getInt();

        cella = bb.order(b).getFloat();
        cellb = bb.order(b).getFloat();
        cellc = bb.order(b).getFloat();
        cellalpha = bb.order(b).getFloat();
        cellbeta = bb.order(b).getFloat();
        cellgamma = bb.order(b).getFloat();

        int axisi[] = new int[3];
        for (int i = 0; i < 3; i++) {
            int axis = bb.order(b).getInt();
            switch (axis) {
            case 1:
                axisi[0] = i;
                break;
            case 2:
                axisi[1] = i;
                break;
            case 3:
                axisi[2] = i;
                break;
            }
        }

        min = bb.order(b).getFloat();
        max = bb.order(b).getFloat();
        mean = bb.order(b).getFloat();

        int sg = bb.order(b).getInt();

        int nsymb = bb.order(b).getInt();

        int skew = bb.order(b).getInt();

        for (int i = 0; i < 12; i++) {
            bb.order(b).getFloat();
        }

        for (int i = 0; i < 15; i++) {
            bb.order(b).getInt();
        }

        byte word[] = new byte[2048];
        bb.order(b).get(word, 0, 4);
        String mapstr = new String(word);
        // System.out.println("MAP?: " + mapstr);

        sd = bb.order(b).getFloat();
        rmsd = bb.order(b).getFloat();

        /*
         System.out.println("col: " + ori[0] + " " + ext[0] + " " + ni[0]);
         System.out.println("row: " + ori[1] + " " + ext[1] + " " + ni[1]);
         System.out.println("sec: " + ori[2] + " " + ext[2] + " " + ni[2]);
         System.out.println("order: " + axisi[0] + " " + axisi[1] + " " + axisi[2]);
         System.out.println("min: " + min + " max: " + max + " mean: " + mean);
         System.out.println("sd: " + sd + " rmsd: " + rmsd);
         System.out.println("sg: " + sg);
         System.out.println("a: " + cella + " b: " + cellb + " c: " + cellc
         + " alpha: " + cellalpha + " beta: " + cellbeta + " gamma: " + cellgamma);
         */
        if (logger.isLoggable(Level.INFO)) {
            StringBuilder sb = new StringBuilder();
            sb.append(String.format("  column origin: %d extent: %d\n", ori[0], ext[0]));
            sb.append(String.format("  row origin: %d extent: %d\n", ori[1], ext[1]));
            sb.append(String.format("  section origin: %d extent: %d\n", ori[2], ext[2]));
            sb.append(String.format("  axis order: %d %d %d\n", axisi[0], axisi[1], axisi[2]));
            sb.append(String.format("  number of X, Y, Z columns: %d %d %d\n", ni[0], ni[1], ni[2]));
            sb.append(String.format("  spacegroup #: %d (name: %s)\n", sg, SpaceGroup.spaceGroupNames[sg - 1]));
            sb.append(String.format("  cell: %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", cella, cellb, cellc,
                    cellalpha, cellbeta, cellgamma));
            logger.info(sb.toString());
        }

        int nlabel = bb.order(b).getInt();

        // System.out.println("nsymb: " + nsymb + " nlabel: " + nlabel);
        for (int i = 0; i < 10; i++) {
            bb.order(b).get(word, 0, 80);
            mapstr = new String(word);
            // System.out.println("label " + i + " : " + mapstr);
        }

        if (nsymb > 0) {
            bb.rewind();
            dis.read(bytes, 0, nsymb);
            for (int i = 0; i < nsymb / 80; i += 80) {
                bb.order(b).get(word, 0, 80);
                mapstr = new String(word);
                // System.out.println("symm: " + mapstr);
            }
        }

        bb.rewind();
        dis.read(bytes, 0, 2048);
        refinementdata.data = new double[ext[0] * ext[1] * ext[2]];
        int ijk[] = new int[3];
        int index, x, y, z;
        refinementdata.ori[0] = ori[axisi[0]];
        refinementdata.ori[1] = ori[axisi[1]];
        refinementdata.ori[2] = ori[axisi[2]];
        int nx = ext[axisi[0]];
        int ny = ext[axisi[1]];
        int nz = ext[axisi[2]];
        refinementdata.ext[0] = nx;
        refinementdata.ext[1] = ny;
        refinementdata.ext[2] = nz;
        refinementdata.ni[0] = ni[0];
        refinementdata.ni[1] = ni[1];
        refinementdata.ni[2] = ni[2];
        for (ijk[2] = 0; ijk[2] < ext[2]; ijk[2]++) {
            for (ijk[1] = 0; ijk[1] < ext[1]; ijk[1]++) {
                for (ijk[0] = 0; ijk[0] < ext[0]; ijk[0]++) {
                    x = ijk[axisi[0]];
                    y = ijk[axisi[1]];
                    z = ijk[axisi[2]];
                    index = x + nx * (y + ny * z);
                    refinementdata.data[index] = bb.order(b).getFloat();
                    if (!bb.hasRemaining()) {
                        bb.rewind();
                        dis.read(bytes, 0, 2048);
                    }
                }
            }
        }
        fis.close();
    } catch (Exception e) {
        String message = "Fatal exception reading CCP4 map.\n";
        logger.log(Level.SEVERE, message, e);
        System.exit(-1);
    }

    return true;
}

From source file:com.sanlq.common.IPIP.java

private void loadToTree() {
    FileInputStream fin = null;// w ww. j a va  2 s  .  c o m
    lock.lock();
    try {
        if (IPDB_FILE_CONTENT == null) {
            IPDB_FILE_CONTENT = readHDFSFile("/data/lib/ipip/ipdb.dat");
        }
        if (IPDB_FILE_CONTENT != null) {
            dataBuffer = ByteBuffer.allocate(Long.valueOf(IPDB_FILE_CONTENT.length).intValue());
            dataBuffer.put(IPDB_FILE_CONTENT);
            dataBuffer.position(0);
            int indexLength = dataBuffer.getInt();
            byte[] indexBytes = new byte[indexLength];
            dataBuffer.get(indexBytes, 0, indexLength - 4);
            indexBuffer = ByteBuffer.wrap(indexBytes);
            indexBuffer.order(ByteOrder.LITTLE_ENDIAN);
            offset = indexLength;
            int loop = 0;
            while (loop++ < 256) {
                index[loop - 1] = indexBuffer.getInt();
            }
            indexBuffer.order(ByteOrder.BIG_ENDIAN);
        }
    } finally {
        lock.unlock();
    }
}

From source file:ubic.gemma.core.analysis.preprocess.batcheffects.AffyScanDateExtractor.java

@SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use
public Date parseGenericCCHeader(DataInputStream str) throws IOException {

    /*/*from w ww .  j  a  v  a2  s.  c  o  m*/
     * acquisition data, intensity data etc. Usually "intensity data" for the first header.
     */
    String datatypeIdentifier = this.readString(str);

    AffyScanDateExtractor.log.debug(datatypeIdentifier);

    String guid = this.readString(str);

    AffyScanDateExtractor.log.debug(guid);

    @SuppressWarnings("unused")
    String createDate = this.readUnicodeString(str); // blank?
    @SuppressWarnings("unused")
    String locale = this.readUnicodeString(str); // e.g. en-US
    int numKeyValuePairs = this.readIntBigEndian(str); // e.g. 55
    Date result = null;
    for (int i = 0; i < numKeyValuePairs; i++) {
        String name = this.readUnicodeString(str);
        byte[] value = this.readBytes(str);
        String type = this.readUnicodeString(str);
        Object v;

        switch (type) {
        case "text/x-calvin-float": {
            FloatBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asFloatBuffer();
            float[] array = new float[intBuf.remaining()];
            intBuf.get(array);
            break;
        }
        case "text/plain":
        case "text/ascii":
            // text/ascii is undocumented, but needed.
            v = new String(value, "US-ASCII");

            if (name.equals("affymetrix-scan-date")) {
                result = this.parseISO8601(new String(((String) v).getBytes(), "UTF-16"));
                AffyScanDateExtractor.log.info("Scan date = " + result);
            }

            if (name.equals("affymetrix-Hyb-Start-Time")) {
                // We don't use this but I'm curious to start looking at it.
                AffyScanDateExtractor.log
                        .info("Hyb start date = " + new String(((String) v).getBytes(), "UTF-16"));
            }

            break;
        case "text-x-calvin-unsigned-integer-8": {
            ShortBuffer intBuf = ByteBuffer.wrap(value).asShortBuffer();
            short[] array = new short[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-integer-16": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer(); // wrong?

            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);
            break;
        }
        case "text/x-calvin-integer-32": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();
            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-unsigned-integer-8": {
            ShortBuffer intBuf = ByteBuffer.wrap(value).asShortBuffer();
            short[] array = new short[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-unsigned-integer-16": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();// wrong?

            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        case "text/x-calvin-unsigned-integer-32": {
            IntBuffer intBuf = ByteBuffer.wrap(value).order(ByteOrder.BIG_ENDIAN).asIntBuffer();
            int[] array = new int[intBuf.remaining()];
            intBuf.get(array);

            break;
        }
        default:
            throw new IOException("Unknown mime type:" + type);
        }

    }

    @SuppressWarnings("unused")
    int numParentHeaders = this.readIntBigEndian(str);
    return result;
}