Package java.io

Examples of java.io.DataInput


     *
     * @return double[]
     */
    public double[] readDoubleArray() {
        try {
            DataInput dis;
            if (bigEndian) {
                dis = new DataInputStream(stream);
            } else {
                dis = new LEDataInputStream(stream);
            }

            Vector<Double> doubleV = new Vector<Double>();

            try {
                while (true) {
                    double f = dis.readDouble();
                    doubleV.add(new Double(f));
                }
            } catch (EOFException eof) {
                stream.close();
            }
View Full Code Here


     *
     * @return double[]
     */
    public double[] readDoubleArray(int n1, int n2) {
        try {
            DataInput dis;
            if (bigEndian) {
                dis = new DataInputStream(stream);
            } else {
                dis = new LEDataInputStream(stream);
            }

            double[] array = new double[n2 - n1];

            dis.skipBytes(n1 * 4);
            for (int i = 0; i < array.length; i++) {
                array[i] = dis.readDouble();
            }

            return array;
        } catch (IOException e) {
            throw new IllegalArgumentException("InputStream is unreadable : "
View Full Code Here

     *
     * @return byte[]
     */
    public byte[] readByteArray() {
        try {
            DataInput dis;
            if (bigEndian) {
                dis = new DataInputStream(stream);
            } else {
                dis = new LEDataInputStream(stream);
            }

            Vector<Byte> bytesV = new Vector<Byte>();

            try {
                while (true) {
                    byte b = dis.readByte();
                    bytesV.add(new Byte(b));
                }
            } catch (EOFException eof) {
                stream.close();
            }
View Full Code Here

        sendFrame(frame);
        int messagesCount = 0;
        int count = 0;
        while (count < 2) {
            String receiveFrame = receiveFrame(10000);
            DataInput input = new DataInputStream(new ByteArrayInputStream(receiveFrame.getBytes()));
            String line;
            while (true) {
                line = input.readLine();
                if (line == null) {
                    throw new IOException("connection was closed");
                }
                else {
                    line = line.trim();
                    if (line.length() > 0) {
                        break;
                    }
                }
            }
            line = input.readLine();
            if (line == null) {
                throw new IOException("connection was closed");
            }
            String messageId = line.substring(line.indexOf(':') + 1);
            messageId = messageId.trim();
            String ackmessage = "ACK\n" + "message-id:" + messageId + "\n\n";
            sendFrame(ackmessage);
            log.debug(receiveFrame);
            //Thread.sleep(1000);
            ++messagesCount;
            ++count;
        }

        sendFrame("DISCONNECT\n\n");
        Thread.sleep(1000);
        stompSocket.close();

        stompSocket = new Socket("localhost", 61613);
        inputBuffer = new ByteArrayOutputStream();

        connect_frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n" + "\n";
        sendFrame(connect_frame);

        f = receiveFrame(5000);

        frame = "SUBSCRIBE\n" + "destination:/queue/" + getDestinationName() + "\n" + "ack:client\n\n";
        sendFrame(frame);
        try {
            while (count != 2000) {
                String receiveFrame = receiveFrame(5000);
                DataInput input = new DataInputStream(new ByteArrayInputStream(receiveFrame.getBytes()));
                String line;
                while (true) {
                    line = input.readLine();
                    if (line == null) {
                        throw new IOException("connection was closed");
                    }
                    else {
                        line = line.trim();
                        if (line.length() > 0) {
                            break;
                        }
                    }
                }

                line = input.readLine();
                if (line == null) {
                    throw new IOException("connection was closed");
                }
                String messageId = line.substring(line.indexOf(':') + 1);
                messageId = messageId.trim();
View Full Code Here

                vertexObject = new JSONObject(line.toString());
            } catch (JSONException e) {
                throw new IllegalArgumentException(
                    "next: Failed to get the vertex", e);
            }
            DataInput input = null;
            byte[] decodedWritable = null;
            I vertexId = null;
            try {
                decodedWritable = Base64.decode(
                    vertexObject.getString(VERTEX_ID_KEY));
View Full Code Here

            dataOut.writeByte(NULL_TYPE);
        }
    }

    public Object unmarshal(DataInput dis) throws IOException {
        DataInput dataIn = dis;
        if( !sizePrefixDisabled ) {
          int size = dis.readInt();
            //byte[] data = new byte[size];
            //dis.readFully(data);
            //bytesIn.restart(data);
View Full Code Here

     * the {@code ByteBuffer.class} key together with the {@code DataInput.class} case.
     *
     * @throws IOException If an error occurred while opening a stream for the input.
     */
    private void createDataInput() throws IOException {
        final DataInput asDataInput;
        if (storage instanceof DataInput) {
            asDataInput = (DataInput) storage;
        } else {
            /*
             * Creates a ChannelImageInputStream instance. We really need that specific type because some
View Full Code Here

            } else if (storage instanceof DataSource) {
                return ((DataSource) storage).getConnection();
            }
        }
        if (type == ImageInputStream.class) {
            final DataInput input = getStorageAs(DataInput.class);
            return (input instanceof ImageInputStream) ? input : null;
        }
        throw new IllegalArgumentException(Errors.format(Errors.Keys.UnknownType_1, type));
    }
View Full Code Here

    /**
     * Implementation of {@link #testGetAsDataInputFromURL()} and {@link #testGetAsDataInputFromStream()}.
     */
    private void testGetAsDataInput(final boolean asStream) throws DataStoreException, IOException {
        final StorageConnector connection = create(asStream);
        final DataInput input = connection.getStorageAs(DataInput.class);
        assertSame("Value shall be cached.", input, connection.getStorageAs(DataInput.class));
        assertInstanceOf("Needs the SIS implementation", ChannelImageInputStream.class, input);
        assertSame("Instance shall be shared.", input, connection.getStorageAs(ChannelDataInput.class));
        /*
         * Reads a single integer for checking that the stream is at the right position, then close the stream.
         * Since the file is a compiled Java class, the integer that we read shall be the Java magic number.
         */
        final ReadableByteChannel channel = ((ChannelImageInputStream) input).channel;
        assertTrue("channel.isOpen()", channel.isOpen());
        assertEquals(MAGIC_NUMBER, input.readInt());
        connection.closeAllExcept(null);
        assertFalse("channel.isOpen()", channel.isOpen());
    }
View Full Code Here

        assertFalse(input instanceof ChannelImageInputStream);
        assertEquals(MAGIC_NUMBER, input.buffer.getInt());
        /*
         * Get as an image input stream and ensure that the cached value has been replaced.
         */
        final DataInput stream = connection.getStorageAs(DataInput.class);
        assertInstanceOf("Needs the SIS implementation", ChannelImageInputStream.class, stream);
        assertNotSame("Expected a new instance.", input, stream);
        assertSame("Shall share the channel.", input.channel, ((ChannelDataInput) stream).channel);
        assertSame("Shall share the buffer.",  input.buffer,  ((ChannelDataInput) stream).buffer);
        assertSame("Cached valud shall have been replaced.", stream, connection.getStorageAs(ChannelDataInput.class));
View Full Code Here

TOP

Related Classes of java.io.DataInput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.