Example usage for java.io DataInputStream readInt

List of usage examples for java.io DataInputStream readInt

Introduction

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

Prototype

public final int readInt() throws IOException 

Source Link

Document

See the general contract of the readInt method of DataInput.

Usage

From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.ClassVersionChecker.java

private void checkClassVersion(String filename) throws IOException {

    DataInputStream in = null;

    try {//from  w ww  .  ja  v a  2 s.c o  m
        //noinspection IOResourceOpenedButNotSafelyClosed
        in = new DataInputStream(new FileInputStream(filename));

        int magic = in.readInt();

        //        The first 4 bytes are a magic number, 0xCAFEBABe, to identify a valid class file
        //        then the next 2 bytes identify the class format version (major and minor).
        //        Possible major/minor value :
        //
        //        major  minor Java platform version
        //        45       3           1.0
        //        45       3           1.1
        //        46       0           1.2
        //        47       0           1.3
        //        48       0           1.4
        //        49       0           1.5
        //        50       0           1.6

        if (magic != 0xcafebabe)
            LOGGER.info(filename + " is not a valid class!");
        int minor = in.readUnsignedShort();
        int major = in.readUnsignedShort();
        LOGGER.info(filename + ": " + major + " . " + minor);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.ryan.ryanreader.cache.PersistentCookieStore.java

public PersistentCookieStore(final byte[] data) throws IOException {

    final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data));

    final int len = dis.readInt();

    for (int i = 0; i < len; i++) {

        final String name = dis.readUTF();
        final String value = dis.readUTF();
        final String domain = dis.readUTF();
        final String path = dis.readUTF();
        final boolean isSecure = dis.readBoolean();

        final BasicClientCookie cookie = new BasicClientCookie(name, value);
        cookie.setDomain(domain);/*from  w  w w.j av a  2s  .  c  o  m*/
        cookie.setPath(path);
        cookie.setSecure(isSecure);

        cookies.add(cookie);
    }
}

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);/*  w  w  w . ja  v  a2 s  .com*/
    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:com.igormaznitsa.jhexed.swing.editor.filecontainer.FileContainer.java

private List<FileContainerSection> loadFromStream(final InputStream in) throws IOException {
    final DataInputStream din = in instanceof DataInputStream ? (DataInputStream) in : new DataInputStream(in);

    if (din.readInt() != MAGIC) {
        throw new IOException("Wrong format, can't find magic");
    }//from  ww  w .  j  ava2s  . c o m

    final int version = din.readShort() & 0xFFFF;

    if (version > FORMAT_VERSION) {
        throw new IllegalArgumentException("Detected unsupported version [" + version + ']');
    }

    final int sectionNumber = din.readUnsignedShort();

    final List<FileContainerSection> result = new ArrayList<FileContainerSection>(Math.max(5, sectionNumber));

    for (int i = 0; i < sectionNumber; i++) {
        final FileContainerSection s = new FileContainerSection(in);
        result.add(s);
    }
    if (din.readInt() != MAGIC) {
        throw new IOException("Can't detecte the end MAGIC");
    }

    return result;
}

From source file:Decoder.java

private byte[] checkAndGetLicenseText(String licenseContent) throws Exception {
    byte[] licenseText;
    try {/*from  w  w w.jav a 2s .c  om*/
        byte[] decodedBytes = Base64.decodeBase64(licenseContent.getBytes());
        ByteArrayInputStream in = new ByteArrayInputStream(decodedBytes);
        DataInputStream dIn = new DataInputStream(in);
        int textLength = dIn.readInt();
        licenseText = new byte[textLength];
        dIn.read(licenseText);
        byte[] hash = new byte[dIn.available()];
        dIn.read(hash);
        try {
            Signature signature = Signature.getInstance("SHA1withDSA");
            signature.initVerify(PUBLIC_KEY);
            signature.update(licenseText);
            if (!signature.verify(hash)) {
                throw new Exception("Failed to verify the license.");
            }

        } catch (InvalidKeyException e) {
            throw new Exception(e);
        } catch (SignatureException e) {
            throw new Exception(e);
        } catch (NoSuchAlgorithmException e) {
            throw new Exception(e);
        }

    } catch (IOException e) {
        throw new Exception(e);
    }

    return licenseText;
}

From source file:ubic.gemma.analysis.preprocess.batcheffects.AffyScanDateExtractor.java

/**
 * @param dis/* w  w w  .  j  a v a2s .c  om*/
 * @return
 * @throws IOException
 */
private int readIntLittleEndian(DataInputStream dis) throws IOException {
    return dis.readInt();
}

From source file:com.igormaznitsa.jhexed.values.HexSVGImageValue.java

public HexSVGImageValue(final InputStream in) throws IOException {
    super(in);/*from   ww  w .ja  v a2s  . c  om*/
    final DataInputStream din = in instanceof DataInputStream ? (DataInputStream) in : new DataInputStream(in);
    final byte[] buffer = new byte[din.readInt()];
    IOUtils.readFully(in, buffer);
    this.image = new SVGImage(new ByteArrayInputStream(buffer), true);
}

From source file:org.nuxeo.apidoc.introspection.BundleIdReader.java

public synchronized void load(File file) {
    DataInputStream in = null;
    try {//from   w ww.j a  v  a2 s.  c  o  m
        in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
        count = in.readLong();
        int size = in.readInt();
        for (int i = 0; i < size; i++) {
            String key = in.readUTF();
            long id = in.readLong();
            ids.put(key, Long.valueOf(id));
        }
    } catch (FileNotFoundException e) {
        // do nothing - this is the first time the runtime is started
    } catch (IOException e) {
        log.error("The bundle.ids file is corrupted. Resetting bundle ids.");
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:com.googlecode.jsendnsca.NagiosPassiveCheckSender.java

private byte[] passiveCheck(MessagePayload payload, DataInputStream inputStream)
        throws IOException, NagiosException {
    final byte[] initVector = readFrom(inputStream);
    int receivedTimeStamp = inputStream.readInt();

    return new PassiveCheckBytesBuilder(nagiosSettings).withTimeStamp(receivedTimeStamp)
            .withLevel(payload.getLevel()).withHostname(payload.getHostname())
            .withServiceName(payload.getServiceName()).withMessage(payload.getMessage()).writeCRC()
            .encrypt(initVector).toByteArray();
}

From source file:ml.shifu.shifu.util.IndependentTreeModelUtils.java

public boolean convertZipSpecToBinary(File zipSpecFile, File outputGbtFile) {
    ZipInputStream zipInputStream = null;
    FileOutputStream fos = null;//from   w ww  .j  a  va2  s  . com

    try {
        zipInputStream = new ZipInputStream(new FileInputStream(zipSpecFile));
        IndependentTreeModel treeModel = null;
        List<List<TreeNode>> trees = null;

        ZipEntry zipEntry = null;
        do {
            zipEntry = zipInputStream.getNextEntry();
            if (zipEntry != null) {
                if (zipEntry.getName().equals(MODEL_CONF)) {
                    ByteArrayOutputStream byos = new ByteArrayOutputStream();
                    IOUtils.copy(zipInputStream, byos);
                    treeModel = JSONUtils.readValue(new ByteArrayInputStream(byos.toByteArray()),
                            IndependentTreeModel.class);
                } else if (zipEntry.getName().equals(MODEL_TREES)) {
                    DataInputStream dataInputStream = new DataInputStream(zipInputStream);
                    int size = dataInputStream.readInt();
                    trees = new ArrayList<List<TreeNode>>(size);
                    for (int i = 0; i < size; i++) {
                        int forestSize = dataInputStream.readInt();
                        List<TreeNode> forest = new ArrayList<TreeNode>(forestSize);
                        for (int j = 0; j < forestSize; j++) {
                            TreeNode treeNode = new TreeNode();
                            treeNode.readFields(dataInputStream);
                            forest.add(treeNode);
                        }
                        trees.add(forest);
                    }
                }
            }
        } while (zipEntry != null);

        if (treeModel != null && CollectionUtils.isNotEmpty(trees)) {
            treeModel.setTrees(trees);
            fos = new FileOutputStream(outputGbtFile);
            treeModel.saveToInputStream(fos);
        } else {
            return false;
        }
    } catch (IOException e) {
        logger.error("Error occurred when convert the zip format model to binary.", e);
        return false;
    } finally {
        IOUtils.closeQuietly(zipInputStream);
        IOUtils.closeQuietly(fos);
    }

    return true;
}