Example usage for java.nio ByteBuffer order

List of usage examples for java.nio ByteBuffer order

Introduction

In this page you can find the example usage for java.nio ByteBuffer order.

Prototype

Endianness order

To view the source code for java.nio ByteBuffer order.

Click Source Link

Document

The byte order of this buffer, default is BIG_ENDIAN .

Usage

From source file:xbird.storage.io.RemoteVarSegments.java

private byte[] recvResponse(final ByteChannel channel, final ByteBuffer rcvBuf) throws IOException {
    ByteBuffer tmpBuf = ByteBuffer.allocate(4);
    NIOUtils.readFully(channel, tmpBuf, 4);
    tmpBuf.flip();//from   www .ja  va  2 s .c  om
    int datalen = tmpBuf.getInt();

    final ByteBuffer buf = truncateBuffer(rcvBuf, datalen);
    NIOUtils.readFully(channel, buf, datalen);
    buf.flip();
    if (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN) {
        buf.order(ByteOrder.BIG_ENDIAN);
    }
    final byte[] b = new byte[datalen];
    buf.get(b);
    if (buf != rcvBuf) {
        _rbufPool.returnObject(buf);
    }
    return b;
}

From source file:com.google.android.apps.body.LayersLoader.java

private void createColorBuffer(DrawGroup drawGroup) {
    int numVertices = drawGroup.vertexBufferData.capacity() / 8; // 3 pos, 3 norm, 2 texcoord

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(numVertices * 2);
    byteBuffer.order(ByteOrder.nativeOrder());
    drawGroup.colorBufferData = byteBuffer.asShortBuffer();

    for (Draw draw : drawGroup.draws) {
        short selectionColor = mMaxColorIndex++;
        mSelectionColorMap.put((int) selectionColor, draw);

        BodyJni.setColorForIndices(drawGroup.colorBufferData, selectionColor, drawGroup.indexBufferData,
                draw.offset, draw.count);
    }/*  w w  w .  j ava2 s. c  o m*/
}

From source file:eu.faircode.netguard.SinkholeService.java

private void startDebug(final ParcelFileDescriptor pfd) {
    if (!debug)/*www. j a va2 s. c  o m*/
        return;

    thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                FileInputStream in = new FileInputStream(pfd.getFileDescriptor());
                FileOutputStream out = new FileOutputStream(pfd.getFileDescriptor());

                ByteBuffer buffer = ByteBuffer.allocate(32767);
                buffer.order(ByteOrder.BIG_ENDIAN);

                Log.i(TAG, "Start receiving");
                while (!Thread.currentThread().isInterrupted() && pfd.getFileDescriptor() != null
                        && pfd.getFileDescriptor().valid())
                    try {
                        buffer.clear();
                        int length = in.read(buffer.array());
                        if (length > 0) {
                            buffer.limit(length);
                            Packet pkt = new Packet(buffer);

                            if (pkt.IPv4.protocol == Packet.IPv4Header.TCP && pkt.TCP.SYN) {
                                int uid = pkt.getUid4();
                                if (uid < 0)
                                    Log.w(TAG, "uid not found");

                                String[] pkg = getPackageManager().getPackagesForUid(uid);
                                if (pkg == null)
                                    pkg = new String[] { uid == 0 ? "root" : "unknown" };

                                Log.i(TAG, "Connect " + pkt.IPv4.destinationAddress + ":"
                                        + pkt.TCP.destinationPort + " uid=" + uid + " pkg=" + pkg[0]);

                                // Send RST
                                pkt.swapAddresses();
                                pkt.TCP.clearFlags();
                                pkt.TCP.RST = true;
                                long ack = pkt.TCP.acknowledgementNumber;
                                pkt.TCP.acknowledgementNumber = (pkt.TCP.sequenceNumber + 1) & 0xFFFFFFFFL;
                                pkt.TCP.sequenceNumber = (ack + 1) & 0xFFFFFFFFL;
                                pkt.send(out);
                            }
                        }
                    } catch (Throwable ex) {
                        Log.e(TAG, ex.toString());
                    }
                Log.i(TAG, "End receiving");
            } catch (Throwable ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            }
        }
    });
    thread.start();
}

From source file:org.apache.htrace.impl.PackedBufferManager.java

private void readAndValidateResponseFrame(SelectionKey sockKey, ByteBuffer buf, long expectedSeq,
        int expectedMethodId) throws IOException {
    buf.clear();//from   w ww.  j  ava  2  s  . c  o  m
    buf.limit(PackedBuffer.HRPC_RESP_FRAME_LENGTH);
    doRecv(sockKey, buf);
    buf.flip();
    buf.order(ByteOrder.LITTLE_ENDIAN);
    long seq = buf.getLong();
    if (seq != expectedSeq) {
        throw new IOException("Expected sequence number " + expectedSeq + ", but got sequence number " + seq);
    }
    int methodId = buf.getInt();
    if (expectedMethodId != methodId) {
        throw new IOException("Expected method id " + expectedMethodId + ", but got " + methodId);
    }
    int errorLength = buf.getInt();
    buf.getInt();
    if ((errorLength < 0) || (errorLength > PackedBuffer.MAX_HRPC_ERROR_LENGTH)) {
        throw new IOException("Got server error with invalid length " + errorLength);
    } else if (errorLength > 0) {
        buf.clear();
        buf.limit(errorLength);
        doRecv(sockKey, buf);
        buf.flip();
        CharBuffer charBuf = StandardCharsets.UTF_8.decode(buf);
        String serverErrorStr = charBuf.toString();
        throw new IOException("Got server error " + serverErrorStr);
    }
}

From source file:io.github.msdk.io.mzdata.MzDataSaxHandler.java

/**
 * {@inheritDoc}//from  ww  w .  j  a v a 2  s.  c om
 *
 * endElement()
 */
@SuppressWarnings("null")
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {

    if (canceled)
        throw new SAXException("Parsing Cancelled");

    // <spectrumInstrument>
    if (qName.equalsIgnoreCase("spectrumInstrument")) {
        spectrumInstrumentFlag = false;
    }

    // <precursor>
    if (qName.equalsIgnoreCase("precursor")) {
        precursorFlag = false;
    }

    // <spectrum>
    if (qName.equalsIgnoreCase("spectrum")) {

        spectrumInstrumentFlag = false;

        // Auto-detect whether this scan is centroided
        MsSpectrumType spectrumType = SpectrumTypeDetectionAlgorithm.detectSpectrumType(mzBuffer,
                intensityBuffer, peaksCount);

        // Create a new scan
        MsFunction msFunction = MSDKObjectBuilder.getMsFunction(msLevel);

        MsScan newScan = MSDKObjectBuilder.getMsScan(dataStore, scanNumber, msFunction);

        newScan.setDataPoints(mzBuffer, intensityBuffer, peaksCount);
        newScan.setSpectrumType(spectrumType);
        newScan.setPolarity(polarity);

        if (retentionTime != null) {
            ChromatographyInfo chromInfo = MSDKObjectBuilder.getChromatographyInfo1D(SeparationType.UNKNOWN,
                    retentionTime);
            newScan.setChromatographyInfo(chromInfo);
        }

        if (precursorMz != null) {
            IsolationInfo isolation = MSDKObjectBuilder.getIsolationInfo(Range.singleton(precursorMz), null,
                    precursorMz, precursorCharge, null);
            newScan.getIsolations().add(isolation);
        }

        // Add the scan to the file
        newRawFile.addScan(newScan);
        parsedScans++;

    }

    // <mzArrayBinary>
    if (qName.equalsIgnoreCase("mzArrayBinary")) {

        mzArrayBinaryFlag = false;

        // Allocate space for the whole array
        if (mzBuffer.length < peaksCount)
            mzBuffer = new double[peaksCount * 2];

        byte[] peakBytes = Base64.decodeBase64(charBuffer.toString().getBytes());

        ByteBuffer currentMzBytes = ByteBuffer.wrap(peakBytes);

        if (endian.equals("big")) {
            currentMzBytes = currentMzBytes.order(ByteOrder.BIG_ENDIAN);
        } else {
            currentMzBytes = currentMzBytes.order(ByteOrder.LITTLE_ENDIAN);
        }

        for (int i = 0; i < peaksCount; i++) {
            if (precision == null || precision.equals("32"))
                mzBuffer[i] = (double) currentMzBytes.getFloat();
            else
                mzBuffer[i] = currentMzBytes.getDouble();
        }

    }

    // <intenArrayBinary>
    if (qName.equalsIgnoreCase("intenArrayBinary")) {

        intenArrayBinaryFlag = false;

        // Allocate space for the whole array
        if (intensityBuffer.length < peaksCount)
            intensityBuffer = new float[peaksCount * 2];

        byte[] peakBytes = Base64.decodeBase64(charBuffer.toString().getBytes());

        ByteBuffer currentIntensityBytes = ByteBuffer.wrap(peakBytes);

        if (endian.equals("big")) {
            currentIntensityBytes = currentIntensityBytes.order(ByteOrder.BIG_ENDIAN);
        } else {
            currentIntensityBytes = currentIntensityBytes.order(ByteOrder.LITTLE_ENDIAN);
        }

        for (int i = 0; i < peaksCount; i++) {
            if (precision == null || precision.equals("32"))
                intensityBuffer[i] = currentIntensityBytes.getFloat();
            else
                intensityBuffer[i] = (float) currentIntensityBytes.getDouble();
        }
    }
}

From source file:au.org.ala.delta.io.BinFile.java

public ByteBuffer readByteBuffer(int size) {
    ByteBuffer bb = ByteBuffer.allocate(size);
    try {/*from   ww w  .j  av  a  2 s  .c o  m*/
        int bytesRead = _channel.read(bb);
        bb.order(ByteOrder.LITTLE_ENDIAN);
        bb.position(0);
        assert bytesRead == size;
    } catch (IOException ioex) {
        throw new RuntimeException(ioex);
    }
    return bb;
}

From source file:ffx.crystal.CCP4MapWriter.java

/**
 * write data to file, does not normalize
 *
 * @param data map data to write out//from   w  ww.ja  v a 2  s  . c  om
 * @param norm should the data be normalized by mean/sd?
 */
public void write(double data[], boolean norm) {
    ByteOrder b = ByteOrder.nativeOrder();
    FileOutputStream fos;
    DataOutputStream dos;

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

    int n = 0;
    for (int k = 0; k < extz; k++) {
        for (int j = 0; j < exty; j++) {
            for (int i = 0; i < extx; i++) {
                int index = stride * (i + extx * (j + exty * k));
                // int index = k * (exty * (extx + 2)) + j * (extx + 2) + i;
                n++;
                if (data[index] < min) {
                    min = data[index];
                }
                if (data[index] > max) {
                    max = data[index];
                }
                mean += (data[index] - mean) / n;
            }
        }
    }

    n = 0;
    for (int k = 0; k < extz; k++) {
        for (int j = 0; j < exty; j++) {
            for (int i = 0; i < extx; i++) {
                int index = stride * (i + extx * (j + exty * k));
                // int index = k * (exty * (extx + 2)) + j * (extx + 2) + i;
                sd += pow(data[index] - mean, 2.0);
                n++;
            }
        }
    }
    sd = sqrt(sd / n);

    if (norm) {
        for (int k = 0; k < extz; k++) {
            for (int j = 0; j < exty; j++) {
                for (int i = 0; i < extx; i++) {
                    int index = stride * (i + extx * (j + exty * k));
                    data[index] = (data[index] - mean) / sd;
                }
            }
        }
        // recurse
        write(data, false);
    }

    try {
        if (logger.isLoggable(Level.INFO)) {
            StringBuilder sb = new StringBuilder();
            sb.append(String.format("\nwriting CCP4 map file: \"%s\"\n", filename));
            sb.append(String.format("map min: %g max: %g mean: %g standard dev.: %g", min, max, mean, sd));
            logger.info(sb.toString());
        }

        fos = new FileOutputStream(filename);
        dos = new DataOutputStream(fos);

        byte bytes[] = new byte[2048];
        int offset = 0;

        int imapdata;
        float fmapdata;
        String mapstr;

        // header
        ByteBuffer bb = ByteBuffer.wrap(bytes);
        bb.order(b).putInt(extx);
        bb.order(b).putInt(exty);
        bb.order(b).putInt(extz);

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

        bb.order(b).putInt(orix);
        bb.order(b).putInt(oriy);
        bb.order(b).putInt(oriz);
        bb.order(b).putInt(nx);
        bb.order(b).putInt(ny);
        bb.order(b).putInt(nz);

        bb.order(b).putFloat((float) crystal.a);
        bb.order(b).putFloat((float) crystal.b);
        bb.order(b).putFloat((float) crystal.c);
        bb.order(b).putFloat((float) crystal.alpha);
        bb.order(b).putFloat((float) crystal.beta);
        bb.order(b).putFloat((float) crystal.gamma);

        bb.order(b).putInt(1);
        bb.order(b).putInt(2);
        bb.order(b).putInt(3);

        bb.order(b).putFloat((float) min);
        bb.order(b).putFloat((float) max);
        bb.order(b).putFloat((float) mean);

        bb.order(b).putInt(crystal.spaceGroup.number);
        // bb.order(b).putInt(1);

        // symmetry bytes - should set this up at some point
        // imapdata = swap ? ByteSwap.swap(320) : 320;
        bb.order(b).putInt(80);

        bb.order(b).putInt(0);

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

        for (int i = 0; i < 15; i++) {
            bb.order(b).putInt(0);
        }
        dos.write(bytes, offset, 208);
        bb.rewind();

        mapstr = "MAP ";
        dos.writeBytes(mapstr);

        // machine code: double, float, int, uchar
        // 0x4441 for LE, 0x1111 for BE
        if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) {
            imapdata = 0x4441;
        } else {
            imapdata = 0x1111;
        }
        bb.order(b).putInt(imapdata);

        bb.order(b).putFloat((float) sd);

        bb.order(b).putInt(1);
        dos.write(bytes, offset, 12);

        StringBuilder sb = new StringBuilder();
        sb.append("map data from ffx");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dos.writeBytes(sb.toString());

        sb = new StringBuilder();
        while (sb.length() < 80) {
            sb.append(" ");
        }
        for (int i = 0; i < 9; i++) {
            dos.writeBytes(sb.toString());
        }

        sb = new StringBuilder();
        sb.append("x,y,z");
        while (sb.length() < 80) {
            sb.append(" ");
        }
        dos.writeBytes(sb.toString());

        bb.rewind();
        for (int k = 0; k < extz; k++) {
            for (int j = 0; j < exty; j++) {
                for (int i = 0; i < extx; i++) {
                    int index = stride * (i + extx * (j + exty * k));
                    // int index = k * (exty * (extx + 2)) + j * (extx + 2) + i;
                    fmapdata = (float) data[index];
                    bb.order(b).putFloat(fmapdata);
                    if (!bb.hasRemaining()) {
                        dos.write(bytes);
                        bb.rewind();
                    }
                }
            }
        }
        if (bb.position() > 0) {
            dos.write(bytes);
            bb.rewind();
        }

        dos.close();
    } catch (Exception e) {
        String message = "Fatal exception evaluating structure factors.\n";
        logger.log(Level.SEVERE, message, e);
        System.exit(-1);
    }
}

From source file:com.linkedin.databus.core.DbusEventV1.java

private static int serializeStringKeyEvent(byte[] key, ByteBuffer serializationBuffer,
        DbusEventInfo eventInfo) {/*  w  ww.  ja va 2s  .  c  o  m*/
    ByteBuffer valueBuffer = eventInfo.getValueByteBuffer();
    int payloadLen = (valueBuffer == null) ? eventInfo.getValueLength() : valueBuffer.remaining();

    int startPosition = serializationBuffer.position();
    byte[] attributes = null;

    // Event without explicit opcode specified should always be considered UPSERT or existing code will break
    if (eventInfo.getOpCode() == DbusOpcode.DELETE) {
        if (serializationBuffer.order() == ByteOrder.BIG_ENDIAN)
            attributes = DeleteStringKeyAttributesBigEndian.clone();
        else
            attributes = DeleteStringKeyAttributesLittleEndian.clone();
    } else {
        if (serializationBuffer.order() == ByteOrder.BIG_ENDIAN)
            attributes = UpsertStringKeyAttributesBigEndian.clone();
        else
            attributes = UpsertStringKeyAttributesLittleEndian.clone();
    }

    if (eventInfo.isEnableTracing()) {
        setTraceFlag(attributes, serializationBuffer.order());
    }

    if (eventInfo.isReplicated())
        setExtReplicationFlag(attributes, serializationBuffer.order());

    serializationBuffer.put(DbusEventFactory.DBUS_EVENT_V1).putInt(HeaderCrcDefault)
            .putInt(StringValueOffset(key.length) + payloadLen).put(attributes)
            .putLong(eventInfo.getSequenceId()).putShort(eventInfo.getpPartitionId())
            .putShort(eventInfo.getlPartitionId()).putLong(eventInfo.getTimeStampInNanos())
            .putShort(eventInfo.getSrcId()).put(eventInfo.getSchemaId(), 0, 16).putInt(HeaderCrcDefault)
            .putInt(key.length).put(key);
    if (valueBuffer != null) {
        // note. put will advance position. In the case of wrapped byte[] it is ok, in the case of
        // ByteBuffer this is actually a read only copy of the buffer passed in.
        serializationBuffer.put(valueBuffer);
    }

    int stopPosition = serializationBuffer.position();
    long valueCrc = ByteBufferCRC32.getChecksum(serializationBuffer, startPosition + StringKeyOffset,
            key.length + payloadLen);
    Utils.putUnsignedInt(serializationBuffer, startPosition + ValueCrcOffset, valueCrc);
    if (eventInfo.isAutocommit()) {
        //TODO (DDSDBUS-61): Medium : can avoid new here
        DbusEventV1 e = new DbusEventV1(serializationBuffer, startPosition);
        e.applyCrc();
    }

    serializationBuffer.position(stopPosition);
    return (stopPosition - startPosition);
}

From source file:nrec.basil.wimuconsole.SensorSettingsActivity.java

private void displayInsData(byte[] ins) {
    TextView t;/*from   w  w  w . j a  va  2  s.c o m*/
    DecimalFormat form = new DecimalFormat("##0.00");
    ByteBuffer insbuffer = ByteBuffer.wrap(ins);
    insbuffer.order(ByteOrder.LITTLE_ENDIAN);
    // Display INS data
    t = (TextView) findViewById(R.id.statusreport);
    String status = null;
    byte stat = insbuffer.get(22);
    if (D)
        Log.d(TAG, "INS Status: " + stat);
    switch (stat) {
    case 0:
        status = "Calibrating";
        break;
    case 1:
        status = "Aligning";
        break;
    case 2:
        status = "Navigating";
        break;
    case 3:
        status = "Invalid Data";
        break;
    case 4:
        status = "Stopped";
        break;
    }
    t.setText(status);

    t = (TextView) findViewById(R.id.solutionreport);
    String solution = null;
    solution = String.format("%8s", Integer.toBinaryString(insbuffer.get(23) & 0xFF)).replace(' ', '0');
    t.setText(solution);

    t = (TextView) findViewById(R.id.px);
    mCurrentLatitude = insbuffer.getDouble(25);
    t.setText(form.format(insbuffer.getDouble(25)));
    t = (TextView) findViewById(R.id.py);
    mCurrentLongitude = insbuffer.getDouble(33);
    t.setText(form.format(insbuffer.getDouble(33)));
    t = (TextView) findViewById(R.id.pz);
    t.setText(form.format(insbuffer.getDouble(41)));
    t = (TextView) findViewById(R.id.vx);
    t.setText(form.format(insbuffer.getDouble(49)));
    t = (TextView) findViewById(R.id.vy);
    t.setText(form.format(insbuffer.getDouble(57)));
    t = (TextView) findViewById(R.id.vz);
    t.setText(form.format(insbuffer.getDouble(65)));
    t = (TextView) findViewById(R.id.ox);
    t.setText(form.format(insbuffer.getDouble(73) * R2D));
    t = (TextView) findViewById(R.id.oy);
    t.setText(form.format(insbuffer.getDouble(81) * R2D));
    t = (TextView) findViewById(R.id.oz);
    t.setText(form.format(insbuffer.getDouble(89) * R2D));
}

From source file:ffx.realspace.CCP4MapFilter.java

/**
 * {@inheritDoc}/*  www.  ja v a  2 s  .  c  o m*/
 */
@Override
public boolean readFile(String filename, RealSpaceRefinementData refinementdata,
        CompositeConfiguration properties) {

    int imapData;
    double cellA, cellB, cellC, cellAlpha, cellBeta, cellGamma;
    String stampString;

    ByteOrder byteOrder = ByteOrder.nativeOrder();
    FileInputStream fileInputStream;
    DataInputStream dataInputStream;

    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 {
        fileInputStream = new FileInputStream(filename);
        dataInputStream = new DataInputStream(fileInputStream);

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

        imapData = byteBuffer.order(ByteOrder.BIG_ENDIAN).getInt();
        stampString = Integer.toHexString(imapData);
        switch (stampString.charAt(0)) {
        case '1':
        case '3':
            if (byteOrder.equals(ByteOrder.LITTLE_ENDIAN)) {
                byteOrder = ByteOrder.BIG_ENDIAN;
            }
            break;
        case '4':
            if (byteOrder.equals(ByteOrder.BIG_ENDIAN)) {
                byteOrder = ByteOrder.LITTLE_ENDIAN;
            }
            break;
        }
        if (logger.isLoggable(Level.INFO)) {
            StringBuilder sb = new StringBuilder();
            sb.append(String.format("\n Opening CCP4 map: %s\n", filename));
            //sb.append(String.format("file type (machine stamp): %s\n", stampString));
            logger.info(sb.toString());
        }

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

    try {
        fileInputStream = new FileInputStream(filename);
        dataInputStream = new DataInputStream(fileInputStream);

        byte bytes[] = new byte[2048];

        dataInputStream.read(bytes, 0, 1024);
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);

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

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

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

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

        cellA = byteBuffer.order(byteOrder).getFloat();
        cellB = byteBuffer.order(byteOrder).getFloat();
        cellC = byteBuffer.order(byteOrder).getFloat();
        cellAlpha = byteBuffer.order(byteOrder).getFloat();
        cellBeta = byteBuffer.order(byteOrder).getFloat();
        cellGamma = byteBuffer.order(byteOrder).getFloat();

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

        min = byteBuffer.order(byteOrder).getFloat();
        max = byteBuffer.order(byteOrder).getFloat();
        mean = byteBuffer.order(byteOrder).getFloat();
        int sg = byteBuffer.order(byteOrder).getInt();
        int nsymb = byteBuffer.order(byteOrder).getInt();
        int skew = byteBuffer.order(byteOrder).getInt();

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

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

        byte word[] = new byte[2048];
        byteBuffer.order(byteOrder).get(word, 0, 4);
        String mapString = new String(word);
        sd = byteBuffer.order(byteOrder).getFloat();
        rmsd = byteBuffer.order(byteOrder).getFloat();

        if (logger.isLoggable(Level.INFO)) {
            StringBuilder sb = new StringBuilder();
            sb.append(String.format("  Column origin:  %d\t Extent: %d\n", ori[0], ext[0]));
            sb.append(String.format("  Row origin:     %d\t Extent: %d\n", ori[1], ext[1]));
            sb.append(String.format("  Section origin: %d\t 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 (%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 = byteBuffer.order(byteOrder).getInt();
        for (int i = 0; i < 10; i++) {
            byteBuffer.order(byteOrder).get(word, 0, 80);
            mapString = new String(word);
        }

        if (nsymb > 0) {
            byteBuffer.rewind();
            dataInputStream.read(bytes, 0, nsymb);
            for (int i = 0; i < nsymb / 80; i += 80) {
                byteBuffer.order(byteOrder).get(word, 0, 80);
                mapString = new String(word);
            }
        }

        byteBuffer.rewind();
        dataInputStream.read(bytes, 0, 2048);
        refinementdata.setData(new double[ext[0] * ext[1] * ext[2]]);
        int ijk[] = new int[3];
        int index, x, y, z;
        refinementdata.setOrigin(ori[axisi[0]], ori[axisi[1]], ori[axisi[2]]);
        int nx = ext[axisi[0]];
        int ny = ext[axisi[1]];
        int nz = ext[axisi[2]];
        refinementdata.setExtent(nx, ny, nz);
        refinementdata.setNI(ni[0], ni[1], 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.getData()[index] = byteBuffer.order(byteOrder).getFloat();
                    if (!byteBuffer.hasRemaining()) {
                        byteBuffer.rewind();
                        dataInputStream.read(bytes, 0, 2048);
                    }
                }
            }
        }
        fileInputStream.close();
    } catch (Exception e) {
        String message = " Fatal exception reading CCP4 map.\n";
        logger.log(Level.SEVERE, message, e);
    }

    return true;
}