Search in sources :

Example 41 with ByteOrder

use of java.nio.ByteOrder in project hazelcast by hazelcast.

the class BinaryCompatibilityFileGenerator method main.

public static void main(String[] args) throws IOException {
    Object[] objects = ReferenceObjects.allTestObjects;
    OutputStream out = new FileOutputStream(createFileName());
    DataOutputStream outputStream = new DataOutputStream(out);
    ByteOrder[] byteOrders = { ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN };
    for (Object object : objects) {
        for (ByteOrder byteOrder : byteOrders) {
            generateBinaryFile(outputStream, object, byteOrder);
        }
    }
    outputStream.close();
}
Also used : DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ByteOrder(java.nio.ByteOrder)

Example 42 with ByteOrder

use of java.nio.ByteOrder in project bytecode-viewer by Konloch.

the class ValuesPanel method longTextFieldKeyReleased.

// GEN-LAST:event_intTextFieldKeyReleased
private void longTextFieldKeyReleased(java.awt.event.KeyEvent evt) {
    // GEN-FIRST:event_longTextFieldKeyReleased
    if (evt.getKeyCode() == KeyEvent.VK_ENTER && isEditable()) {
        try {
            ByteOrder byteOrder = getByteOrder();
            if (isSigned()) {
                long longValue = Long.parseLong(longTextField.getText());
                byteBuffer.rewind();
                if (byteBuffer.order() != byteOrder) {
                    byteBuffer.order(byteOrder);
                }
                byteBuffer.putLong(longValue);
            } else {
                BigInteger bigInteger = new BigInteger(longTextField.getText());
                if (bigInteger.signum() == -1 || bigInteger.compareTo(ULONG_MAX_VALUE) > 0) {
                    throw new NumberFormatException(VALUE_OUT_OF_RANGE);
                }
                if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                    for (int i = 0; i < 7; i++) {
                        BigInteger nextByte = bigInteger.and(BIG_INTEGER_BYTE_MASK);
                        valuesCache[7 - i] = nextByte.byteValue();
                        bigInteger = bigInteger.shiftRight(8);
                    }
                } else {
                    for (int i = 0; i < 7; i++) {
                        BigInteger nextByte = bigInteger.and(BIG_INTEGER_BYTE_MASK);
                        valuesCache[i] = nextByte.byteValue();
                        bigInteger = bigInteger.shiftRight(8);
                    }
                }
            }
            modifyValues(8);
            updateValues();
        } catch (NumberFormatException ex) {
            showException(ex);
        }
    }
}
Also used : BigInteger(java.math.BigInteger) ByteOrder(java.nio.ByteOrder)

Example 43 with ByteOrder

use of java.nio.ByteOrder in project bytecode-viewer by Konloch.

the class ValuesPanel method floatTextFieldKeyReleased.

// GEN-LAST:event_longTextFieldKeyReleased
private void floatTextFieldKeyReleased(java.awt.event.KeyEvent evt) {
    // GEN-FIRST:event_floatTextFieldKeyReleased
    if (evt.getKeyCode() == KeyEvent.VK_ENTER && isEditable()) {
        try {
            ByteOrder byteOrder = getByteOrder();
            float floatValue = Float.parseFloat(floatTextField.getText());
            byteBuffer.rewind();
            if (byteBuffer.order() != byteOrder) {
                byteBuffer.order(byteOrder);
            }
            byteBuffer.putFloat(floatValue);
            modifyValues(4);
            updateValues();
        } catch (NumberFormatException ex) {
            showException(ex);
        }
    }
}
Also used : ByteOrder(java.nio.ByteOrder)

Example 44 with ByteOrder

use of java.nio.ByteOrder in project hs4j by killme2008.

the class AbstractIoBuffer method capacity.

/**
 * {@inheritDoc}
 */
@Override
public final IoBuffer capacity(int newCapacity) {
    if (!recapacityAllowed) {
        throw new IllegalStateException("Derived buffers and their parent can't be expanded.");
    }
    // Allocate a new buffer and transfer all settings to it.
    if (newCapacity > capacity()) {
        // Expand:
        // // Save the state.
        int pos = position();
        int limit = limit();
        ByteOrder bo = order();
        // // Reallocate.
        ByteBuffer oldBuf = buf();
        ByteBuffer newBuf = getAllocator().allocateNioBuffer(newCapacity, isDirect());
        oldBuf.clear();
        newBuf.put(oldBuf);
        buf(newBuf);
        // // Restore the state.
        buf().limit(limit);
        if (mark >= 0) {
            buf().position(mark);
            buf().mark();
        }
        buf().position(pos);
        buf().order(bo);
    }
    return this;
}
Also used : ByteOrder(java.nio.ByteOrder) ByteBuffer(java.nio.ByteBuffer)

Example 45 with ByteOrder

use of java.nio.ByteOrder in project hazelcast by hazelcast.

the class ObjectDataOutputStreamTest method testGetByteOrder.

@Test
public void testGetByteOrder() throws Exception {
    ByteOrder byteOrderActual = dataOutputStream.getByteOrder();
    assertEquals(serializationService.getByteOrder(), byteOrderActual);
}
Also used : ByteOrder(java.nio.ByteOrder) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ByteOrder (java.nio.ByteOrder)111 ByteBuffer (java.nio.ByteBuffer)39 IOException (java.io.IOException)8 Test (org.junit.Test)7 QuickTest (com.hazelcast.test.annotation.QuickTest)5 DataInputStream (java.io.DataInputStream)5 FileInputStream (java.io.FileInputStream)5 UUID (java.util.UUID)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 HKL (ffx.crystal.HKL)3 DataOutputStream (java.io.DataOutputStream)3 EOFException (java.io.EOFException)3 FileOutputStream (java.io.FileOutputStream)3 ShortBuffer (java.nio.ShortBuffer)3 ArrayList (java.util.ArrayList)3 Element (org.jdom.Element)3 InvalidDumpFormatException (com.ibm.j9ddr.corereaders.InvalidDumpFormatException)2 Point (com.revolsys.geometry.model.Point)2 Crystal (ffx.crystal.Crystal)2 BigInteger (java.math.BigInteger)2