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:uk.ac.ebi.mdk.io.ReactionMatrixIO.java

public static StoichiometricMatrix readCompressedBasicStoichiometricMatrix(InputStream stream,
        StoichiometricMatrix s) throws IOException {

    DataInputStream in = new DataInputStream(stream);

    int n = in.readInt();
    int m = in.readInt();

    s.ensure(n, m);//from   ww  w. j av a  2  s.c  om

    for (int j = 0; j < m; j++) {
        s.setReaction(j, in.readUTF());
    }

    for (int i = 0; i < n; i++) {
        s.setMolecule(i, in.readUTF());
    }

    boolean convert = in.readBoolean();
    int size = in.readInt();

    while (--size >= 0) {

        int i = in.readInt();
        int j = in.readInt();
        Object value = convert ? in.readInt() : in.readDouble();
        Double dValue = value instanceof Double ? (Double) value : ((Integer) value).doubleValue();
        s.setValue(i, j, dValue);
    }

    in.close();

    return s;

}

From source file:com.csc.fi.ioapi.utils.JerseyJsonLDClient.java

public static Boolean readBooleanFromURL(String url) {
    try {/*from   www  .jav  a2  s . co  m*/

        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(url);
        Response response = target.request("application/json").get();

        if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
            logger.info("Failed to read boolean from: " + url + " " + response.getStatus());
            return Boolean.FALSE;
        }

        DataInputStream dis = new DataInputStream(response.readEntity(InputStream.class));
        return new Boolean(dis.readBoolean());

    } catch (Exception ex) {
        logger.info("Failed in reading boolean from URL ... returning false");
        return Boolean.FALSE;
    }
}

From source file:Main.java

public static Object[] readSettings(String file) throws IOException {
    DataInputStream in = new DataInputStream(new FileInputStream(file));
    try {/*from  w  w w  . j  a va2s . c o  m*/
        Object[] res = new Object[in.readInt()];
        for (int i = 0; i < res.length; i++) {
            char cl = in.readChar();
            switch (cl) {
            case 'S':
                res[i] = in.readUTF();
                break;
            case 'F':
                res[i] = in.readFloat();
                break;
            case 'D':
                res[i] = in.readDouble();
                break;
            case 'I':
                res[i] = in.readInt();
                break;
            case 'L':
                res[i] = in.readLong();
                break;
            case 'B':
                res[i] = in.readBoolean();
                break;
            case 'Y':
                res[i] = in.readByte();
                break;
            default:
                throw new IllegalStateException("cannot read type " + cl + " from " + file);
            }
        }
        return res;
    } finally {
        in.close();
    }
}

From source file:com.google.gwt.dev.javac.CachedCompilationUnit.java

public static CachedCompilationUnit load(InputStream inputStream, JsProgram jsProgram) throws Exception {
    DataInputStream dis = new DataInputStream(new BufferedInputStream(inputStream));
    try {//from w w  w. j a  va 2 s .  c o m
        CachedCompilationUnit compilationUnit = new CachedCompilationUnit();
        // version
        long version = dis.readLong();
        if (version != CompilationUnitDiskCache.CACHE_VERSION) {
            return null;
        }
        // some simple stuff :)
        compilationUnit.m_lastModified = dis.readLong();
        compilationUnit.m_displayLocation = dis.readUTF();
        compilationUnit.m_typeName = dis.readUTF();
        compilationUnit.m_contentId = new ContentId(dis.readUTF());
        compilationUnit.m_isSuperSource = dis.readBoolean();
        // compiled classes
        {
            int size = dis.readInt();
            compilationUnit.m_compiledClasses = new ArrayList<CompiledClass>(size);
            for (int i = 0; i < size; ++i) {
                // internal name
                String internalName = dis.readUTF();
                // is local
                boolean isLocal = dis.readBoolean();
                // bytes
                int byteSize = dis.readInt();
                byte[] bytes = new byte[byteSize];
                dis.readFully(bytes);
                // enclosing class
                CompiledClass enclosingClass = null;
                String enclosingClassName = dis.readUTF();
                if (!StringUtils.isEmpty(enclosingClassName)) {
                    for (CompiledClass cc : compilationUnit.m_compiledClasses) {
                        if (enclosingClassName.equals(cc.getInternalName())) {
                            enclosingClass = cc;
                            break;
                        }
                    }
                }
                // some assertion
                if (!StringUtils.isEmpty(enclosingClassName) && enclosingClass == null) {
                    throw new IllegalStateException("Can't find the enclosing class \"" + enclosingClassName
                            + "\" for \"" + internalName + "\"");
                }
                // init unit
                CompiledClass cc = new CompiledClass(internalName, bytes, isLocal, enclosingClass);
                cc.initUnit(compilationUnit);
                compilationUnit.m_compiledClasses.add(cc);
            }
        }
        // dependencies
        {
            compilationUnit.m_dependencies = new HashSet<ContentId>();
            int size = dis.readInt();
            if (size > 0) {
                for (int i = 0; i < size; i++) {
                    compilationUnit.m_dependencies.add(new ContentId(dis.readUTF()));
                }
            }
        }
        // JSNI methods
        {
            compilationUnit.m_jsniMethods = new ArrayList<JsniMethod>();
            int size = dis.readInt();
            if (size > 0) {
                for (int i = 0; i < size; i++) {
                    String name = dis.readUTF();
                    int startPos = dis.readInt();
                    int endPos = dis.readInt();
                    int startLine = dis.readInt();
                    String source = dis.readUTF();
                    String fileName = compilationUnit.m_displayLocation;
                    SourceInfo jsInfo = SourceOrigin.create(startPos, endPos, startLine, fileName);
                    compilationUnit.m_jsniMethods
                            .add(JsniCollector.restoreJsniMethod(name, source, jsInfo, jsProgram));
                }
            }
        }
        // Method lookup
        {
            compilationUnit.m_methodArgs = MethodArgNamesLookup.load(dis);
        }
        return compilationUnit;
    } finally {
        IOUtils.closeQuietly(dis);
    }
}

From source file:org.apache.cassandra.db.SliceByNamesReadCommand.java

@Override
public ReadCommand deserialize(DataInputStream dis) throws IOException {
    boolean isDigest = dis.readBoolean();
    String table = dis.readUTF();
    String key = dis.readUTF();//from w  ww .  j av  a 2 s .co m
    QueryPath columnParent = QueryPath.deserialize(dis);

    int size = dis.readInt();
    List<byte[]> columns = new ArrayList<byte[]>();
    for (int i = 0; i < size; ++i) {
        columns.add(ColumnSerializer.readName(dis));
    }
    SliceByNamesReadCommand rm = new SliceByNamesReadCommand(table, key, columnParent, columns);
    rm.setDigestQuery(isDigest);
    return rm;
}

From source file:org.getspout.spout.packet.PacketBlockData.java

public void readData(DataInputStream input) throws IOException {
    int size = input.readInt();
    compressed = input.readBoolean();
    if (size > 0) {
        data = new byte[size];
        input.readFully(data);//from w w  w.  j a v a2 s. co  m
    }
}

From source file:com.bigdata.dastor.db.ReadResponse.java

public ReadResponse deserialize(DataInputStream dis) throws IOException {
    int digestSize = dis.readInt();
    byte[] digest = new byte[digestSize];
    dis.read(digest, 0, digestSize);//from   w w w  .j a v a2  s .co m
    boolean isDigest = dis.readBoolean();

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

    ReadResponse rmsg = isDigest ? new ReadResponse(digest) : new ReadResponse(row);
    rmsg.setIsDigestQuery(isDigest);
    return rmsg;
}

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

private <T> boolean invokeRemoteBoolean(final String methodName, final T value, final Serializer<T> serializer)
        throws IOException {
    if (closed) {
        throw new IllegalStateException("Client is closed");
    }/*from  w  ww . ja  v  a  2s. co m*/

    final CommsSession session = leaseCommsSession();
    boolean tryToRequeue = true;
    try {
        final DataOutputStream dos = new DataOutputStream(session.getOutputStream());
        dos.writeUTF(methodName);

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        serializer.serialize(value, baos);
        dos.writeInt(baos.size());
        baos.writeTo(dos);
        dos.flush();

        final DataInputStream dis = new DataInputStream(session.getInputStream());
        return dis.readBoolean();
    } catch (final IOException ioe) {
        tryToRequeue = false;
        throw ioe;
    } finally {
        if (tryToRequeue == true && this.closed == false) {
            queue.offer(session);
        } else {
            IOUtils.closeQuietly(session);
        }
    }
}

From source file:org.getspout.spout.packet.PacketCacheFile.java

public void readData(DataInputStream input) throws IOException {
    this.fileName = PacketUtil.readString(input);
    this.plugin = PacketUtil.readString(input);
    compressed = input.readBoolean();
    int size = input.readInt();
    this.fileData = new byte[size];
    input.readFully(this.fileData);
}

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

private IColumn defreeze(DataInputStream dis, String name) throws IOException {
    IColumn column = null;//from w  ww  .  j ava  2  s  . c  o  m
    boolean delete = dis.readBoolean();
    long ts = dis.readLong();
    int size = dis.readInt();
    byte[] value = new byte[size];
    dis.readFully(value);
    column = new Column(name, value, ts, delete);
    return column;
}