Example usage for java.io DataInputStream readBoolean

List of usage examples for java.io DataInputStream readBoolean

Introduction

In this page you can find the example usage for java.io DataInputStream readBoolean.

Prototype

public final boolean readBoolean() throws IOException 

Source Link

Document

See the general contract of the readBoolean method of DataInput.

Usage

From source file:org.spoutcraft.client.packet.PacketEntityInformation.java

public void readData(DataInputStream input) throws IOException {
    int size = input.readInt();
    if (size > 0) {
        data = new byte[size];
        input.readFully(data);/*from   w  ww . java  2s .c  o  m*/
    }
    compressed = input.readBoolean();
}

From source file:com.facebook.infrastructure.db.ReadResponse.java

public ReadResponse deserialize(DataInputStream dis) throws IOException {
    String table = dis.readUTF();
    int digestSize = dis.readInt();
    byte[] digest = new byte[digestSize];
    dis.read(digest, 0, digestSize);/*from  ww  w .ja va2 s  .  c  o  m*/
    boolean isDigest = dis.readBoolean();

    Row row = null;
    if (!isDigest) {
        row = Row.serializer().deserialize(dis);
    }

    ReadResponse rmsg = null;
    if (isDigest) {
        rmsg = new ReadResponse(table, digest);
    } else {
        rmsg = new ReadResponse(table, row);
    }
    rmsg.setIsDigestQuery(isDigest);
    return rmsg;
}

From source file:org.slc.sli.dal.encrypt.AesCipher.java

private Object decryptBinary(String data, Class<?> expectedType) {
    byte[] decoded = decryptToBytes(data);
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(decoded));
    try {//from ww w . ja v a  2  s . co m
        if (Boolean.class.equals(expectedType)) {
            return dis.readBoolean();
        } else if (Integer.class.equals(expectedType)) {
            return dis.readInt();
        } else if (Long.class.equals(expectedType)) {
            return dis.readLong();
        } else if (Double.class.equals(expectedType)) {
            return dis.readDouble();
        } else {
            throw new RuntimeException("Unsupported type: " + expectedType.getCanonicalName());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            dis.close();
        } catch (IOException e) {
            LOG.error("Unable to close DataInputStream!");
        }
    }
}

From source file:gridool.util.xfer.RecievedFileWriter.java

public final void handleRequest(@Nonnull final SocketChannel inChannel, @Nonnull final Socket socket)
        throws IOException {
    final StopWatch sw = new StopWatch();
    if (!inChannel.isBlocking()) {
        inChannel.configureBlocking(true);
    }/*from   w  w  w .j a v  a2s  . c  o m*/

    InputStream in = socket.getInputStream();
    DataInputStream dis = new DataInputStream(in);

    String fname = IOUtils.readString(dis);
    String dirPath = IOUtils.readString(dis);
    long len = dis.readLong();
    boolean append = dis.readBoolean();
    boolean ackRequired = dis.readBoolean();
    boolean hasAdditionalHeader = dis.readBoolean();
    if (hasAdditionalHeader) {
        readAdditionalHeader(dis, fname, dirPath, len, append, ackRequired);
    }

    final File file;
    if (dirPath == null) {
        file = new File(baseDir, fname);
    } else {
        File dir = FileUtils.resolvePath(baseDir, dirPath);
        file = new File(dir, fname);
    }

    preFileAppend(file, append);
    final FileOutputStream dst = new FileOutputStream(file, append);
    final String fp = file.getAbsolutePath();
    final ReadWriteLock filelock = accquireLock(fp, locks);
    final FileChannel fileCh = dst.getChannel();
    final long startPos = file.length();
    try {
        NIOUtils.transferFully(inChannel, 0, len, fileCh); // REVIEWME really an atomic operation?
    } finally {
        IOUtils.closeQuietly(fileCh, dst);
        releaseLock(fp, filelock, locks);
        postFileAppend(file, startPos, len);
    }
    if (ackRequired) {
        OutputStream out = socket.getOutputStream();
        DataOutputStream dos = new DataOutputStream(out);
        dos.writeLong(len);
        postAck(file, startPos, len);
    }

    if (LOG.isDebugEnabled()) {
        SocketAddress remoteAddr = socket.getRemoteSocketAddress();
        LOG.debug("Received a " + (append ? "part of file '" : "file '") + file.getAbsolutePath() + "' of "
                + len + " bytes from " + remoteAddr + " in " + sw.toString());
    }
}

From source file:xbird.util.xfer.RecievedFileWriter.java

public final void handleRequest(@Nonnull final SocketChannel inChannel, @Nonnull final Socket socket)
        throws IOException {
    final StopWatch sw = new StopWatch();
    if (!inChannel.isBlocking()) {
        inChannel.configureBlocking(true);
    }//from  w  w w  . ja va 2 s . c o  m

    InputStream in = socket.getInputStream();
    DataInputStream dis = new DataInputStream(in);

    String fname = IOUtils.readString(dis);
    String dirPath = IOUtils.readString(dis);
    long len = dis.readLong();
    boolean append = dis.readBoolean();
    boolean ackRequired = dis.readBoolean();
    boolean hasAdditionalHeader = dis.readBoolean();
    if (hasAdditionalHeader) {
        readAdditionalHeader(dis, fname, dirPath, len, append, ackRequired);
    }

    final File file;
    if (dirPath == null) {
        file = new File(baseDir, fname);
    } else {
        File dir = FileUtils.resolvePath(baseDir, dirPath);
        file = new File(dir, fname);
    }

    preFileAppend(file, append);
    final FileOutputStream dst = new FileOutputStream(file, append);
    final String fp = file.getAbsolutePath();
    final ReadWriteLock filelock = accquireLock(fp, locks);
    final FileChannel fileCh = dst.getChannel();
    final long startPos = file.length();
    try {
        NIOUtils.transferFullyFrom(inChannel, 0, len, fileCh); // REVIEWME really an atomic operation?
    } finally {
        IOUtils.closeQuietly(fileCh, dst);
        releaseLock(fp, filelock, locks);
        postFileAppend(file, startPos, len);
    }
    if (ackRequired) {
        OutputStream out = socket.getOutputStream();
        DataOutputStream dos = new DataOutputStream(out);
        dos.writeLong(len);
        postAck(file, startPos, len);
    }

    if (LOG.isDebugEnabled()) {
        SocketAddress remoteAddr = socket.getRemoteSocketAddress();
        LOG.debug("Received a " + (append ? "part of file '" : "file '") + file.getAbsolutePath() + "' of "
                + len + " bytes from " + remoteAddr + " in " + sw.toString());
    }
}

From source file:com.facebook.infrastructure.db.Column.java

public void skip(DataInputStream dis) throws IOException {
    /* read the column name */
    dis.readUTF();/*  ww  w  .j av a2s.c om*/
    /* boolean indicating if the column is deleted */
    dis.readBoolean();
    /* timestamp associated with the column */
    dis.readLong();
    /* size of the column */
    int size = dis.readInt();
    dis.skip(size);
}

From source file:J2MEWriteReadMixedDataTypesExample.java

public void commandAction(Command command, Displayable displayable) {
    if (command == exit) {
        destroyApp(true);/*w w w.j  av  a  2 s.  co  m*/
        notifyDestroyed();
    } else if (command == start) {
        try {
            recordstore = RecordStore.openRecordStore("myRecordStore", true);
            byte[] outputRecord;
            String outputString = "First Record";
            int outputInteger = 15;
            boolean outputBoolean = true;
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            DataOutputStream outputDataStream = new DataOutputStream(outputStream);
            outputDataStream.writeUTF(outputString);
            outputDataStream.writeBoolean(outputBoolean);
            outputDataStream.writeInt(outputInteger);
            outputDataStream.flush();
            outputRecord = outputStream.toByteArray();
            recordstore.addRecord(outputRecord, 0, outputRecord.length);
            outputStream.reset();
            outputStream.close();
            outputDataStream.close();
            String inputString = null;
            int inputInteger = 0;
            boolean inputBoolean = false;
            byte[] byteInputData = new byte[100];
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
            DataInputStream inputDataStream = new DataInputStream(inputStream);
            for (int x = 1; x <= recordstore.getNumRecords(); x++) {
                recordstore.getRecord(x, byteInputData, 0);
                inputString = inputDataStream.readUTF();
                inputBoolean = inputDataStream.readBoolean();
                inputInteger = inputDataStream.readInt();
                inputStream.reset();
            }
            inputStream.close();
            inputDataStream.close();
            alert = new Alert("Reading", inputString + " " + inputInteger + " " + inputBoolean, null,
                    AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
            recordstore.closeRecordStore();
            if (RecordStore.listRecordStores() != null) {
                RecordStore.deleteRecordStore("myRecordStore");
            }
        } catch (Exception error) {
            alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            display.setCurrent(alert);
        }
    }
}

From source file:org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService.java

@Override
public <K> boolean containsKey(final K key, final Serializer<K> keySerializer) throws IOException {
    return withCommsSession(new CommsAction<Boolean>() {
        @Override//  w  w  w .j  a  v a  2  s .  c o  m
        public Boolean execute(final CommsSession session) throws IOException {
            final DataOutputStream dos = new DataOutputStream(session.getOutputStream());
            dos.writeUTF("containsKey");

            serialize(key, keySerializer, dos);
            dos.flush();

            final DataInputStream dis = new DataInputStream(session.getInputStream());
            return dis.readBoolean();
        }
    });
}

From source file:org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService.java

@Override
public <K, V> boolean replace(final K key, final V value, final Serializer<K> keySerializer,
        final Serializer<V> valueSerializer, final long revision) throws IOException {
    return withCommsSession(session -> {
        validateProtocolVersion(session, 2);

        final DataOutputStream dos = new DataOutputStream(session.getOutputStream());
        dos.writeUTF("replace");

        serialize(key, keySerializer, dos);
        dos.writeLong(revision);/*  w  w  w  .j  a v  a  2s.  c  o  m*/
        serialize(value, valueSerializer, dos);

        dos.flush();

        // read response
        final DataInputStream dis = new DataInputStream(session.getInputStream());
        return dis.readBoolean();
    });
}

From source file:org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService.java

@Override
public <K> boolean remove(final K key, final Serializer<K> serializer) throws IOException {
    return withCommsSession(new CommsAction<Boolean>() {
        @Override//  www .  ja  v a2s  . c  om
        public Boolean execute(final CommsSession session) throws IOException {
            final DataOutputStream dos = new DataOutputStream(session.getOutputStream());
            dos.writeUTF("remove");

            serialize(key, serializer, dos);
            dos.flush();

            // read response
            final DataInputStream dis = new DataInputStream(session.getInputStream());
            return dis.readBoolean();
        }
    });
}