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:com.igormaznitsa.jhexed.renders.svg.SVGImage.java

public SVGImage(final InputStream in, final boolean packed) throws IOException {
    final DataInputStream din = in instanceof DataInputStream ? (DataInputStream) in : new DataInputStream(in);
    if (packed) {
        final byte[] packedImageData = new byte[din.readInt()];
        IOUtils.readFully(din, packedImageData);
        this.originalNonParsedImageData = Utils.unpackArray(packedImageData);
    } else {// w w w .j a  va  2 s.  c  o m
        this.originalNonParsedImageData = readFullInputStream(din);
    }
    this.quality = din.readBoolean();

    this.svgGraphicsNode = loadDiagramFromStream(new ByteArrayInputStream(this.originalNonParsedImageData),
            this.documentSize);
}

From source file:org.spout.engine.filesystem.WorldFiles.java

public static void readColumn(InputStream in, SpoutColumn column, AtomicInteger lowestY,
        BlockMaterial[][] topmostBlocks) {
    if (in == null) {
        //The inputstream is null because no height map data exists
        for (int x = 0; x < SpoutColumn.BLOCKS.SIZE; x++) {
            for (int z = 0; z < SpoutColumn.BLOCKS.SIZE; z++) {
                column.getAtomicInteger(x, z).set(Integer.MIN_VALUE);
                topmostBlocks[x][z] = null;
                column.setDirty(x, z);/*from  w w  w .ja v a2s .c  o m*/
            }
        }
        lowestY.set(Integer.MAX_VALUE);
        return;
    }

    DataInputStream dataStream = new DataInputStream(in);
    try {
        for (int x = 0; x < SpoutColumn.BLOCKS.SIZE; x++) {
            for (int z = 0; z < SpoutColumn.BLOCKS.SIZE; z++) {
                column.getAtomicInteger(x, z).set(dataStream.readInt());
            }
        }
        @SuppressWarnings("unused")
        int version = dataStream.readInt();

        lowestY.set(dataStream.readInt());

        //Save heightmap
        StringMap global = ((SpoutEngine) Spout.getEngine()).getEngineItemMap();
        StringMap itemMap = column.getWorld().getItemMap();
        boolean warning = false;
        for (int x = 0; x < SpoutColumn.BLOCKS.SIZE; x++) {
            for (int z = 0; z < SpoutColumn.BLOCKS.SIZE; z++) {
                if (!dataStream.readBoolean()) {
                    continue;
                }
                int blockState = dataStream.readInt();
                short blockId = BlockFullState.getId(blockState);
                short blockData = BlockFullState.getData(blockState);
                blockId = (short) itemMap.convertTo(global, blockId);
                blockState = BlockFullState.getPacked(blockId, blockData);
                BlockMaterial m;
                try {
                    m = (BlockMaterial) MaterialRegistry.get(blockState);
                } catch (ClassCastException e) {
                    m = null;
                    if (!warning) {
                        Spout.getLogger().severe(
                                "Error reading column topmost block information, block was not a valid BlockMaterial");
                        warning = false;
                    }
                }
                if (m == null) {
                    column.setDirty(x, z);
                }
                topmostBlocks[x][z] = m;
            }
        }

        //Save Biomes
        BiomeManager manager = null;
        try {
            //Biome manager is serialized with:
            // - boolean, if a biome manager exists
            // - String, the class name
            // - int, the number of bytes of data to read
            // - byte[], size of the above int in length
            boolean exists = dataStream.readBoolean();
            if (exists) {
                String biomeManagerClass = dataStream.readUTF();
                int biomeSize = dataStream.readInt();
                byte[] biomes = new byte[biomeSize];
                dataStream.readFully(biomes);

                //Attempt to create the biome manager class from the class name
                @SuppressWarnings("unchecked")
                Class<? extends BiomeManager> clazz = (Class<? extends BiomeManager>) Class
                        .forName(biomeManagerClass);
                Class<?>[] params = { int.class, int.class };
                manager = clazz.getConstructor(params).newInstance(column.getX(), column.getZ());
                manager.deserialize(biomes);
                column.setBiomeManager(manager);
            }
        } catch (Exception e) {
            Spout.getLogger().log(Level.SEVERE, "Failed to read biome data for column", e);
        }

    } catch (IOException e) {
        Spout.getLogger()
                .severe("Error reading column height-map for column" + column.getX() + ", " + column.getZ());
    }
}

From source file:org.veronicadb.core.memorygraph.storage.SimpleLocalFileStorageSink.java

protected List<VEdge> readVertexEdge(VSubGraph graph, long vertexId, DataInputStream stream)
        throws IOException {
    int edgeCount = stream.readInt();
    List<VEdge> edges = new ArrayList<VEdge>(edgeCount);
    for (int i = 0; i < edgeCount; i++) {
        long edgeId = readElementId(stream);
        String edgeLabel = readElementLabel(stream);
        boolean direction = stream.readBoolean();
        boolean sharedShard = stream.readBoolean();
        VSubGraph graphTwo = null;// w  ww.j  a v a 2  s  . c o  m
        if (sharedShard) {
            graphTwo = graph;
        } else {
            long graphTwoId = readElementId(stream);
            if (getGraph() != null) {
                graphTwo = getGraph().getGraphShard(graphTwoId);
            } else {
                graphTwo = new VSubGraph(graphTwoId, 1);
            }
        }
        long otherVertexId = readElementId(stream);
        if (direction) {
            VEdge edge = new VEdge(edgeId, edgeLabel, otherVertexId, graphTwo, vertexId, graph);
            edges.add(edge);
        } else {
            VEdge edge = new VEdge(edgeId, edgeLabel, vertexId, graph, otherVertexId, graphTwo);
            edges.add(edge);
        }
    }
    return edges;
}

From source file:BugTracker.java

private void loadBugs() {
    // Load bugs from a file.
    DataInputStream in = null;

    try {//  w  w w.  j  av a  2s  .  c  om
        File file = new File("bugs.dat");
        if (!file.exists())
            return;
        in = new DataInputStream(new FileInputStream(file));

        while (true) {
            String id = in.readUTF();
            String summary = in.readUTF();
            String assignedTo = in.readUTF();
            boolean solved = in.readBoolean();

            TableItem item = new TableItem(table, SWT.NULL);
            item.setImage(bugIcon);
            item.setText(new String[] { id, summary, assignedTo, solved ? "Yes" : "No" });
        }

    } catch (IOException ioe) {
        // Ignore.

    } finally {
        try {
            if (in != null)
                in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:ubic.basecode.io.ByteArrayConverter.java

/**
 * @param barray//from w ww.ja v  a 2 s . c o m
 * @return boolean[]
 */
public boolean[] byteArrayToBooleans(byte[] barray) {
    if (barray == null)
        return null;
    ByteArrayInputStream bis = new ByteArrayInputStream(barray);
    DataInputStream dis = new DataInputStream(bis);
    boolean[] iarray = new boolean[barray.length / BOOL_SIZE];
    int i = 0;

    try {
        while (dis.available() > 0) {
            iarray[i] = dis.readBoolean();
            i++;
        }
        return iarray;

    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            dis.close();
            bis.close();

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

        }
    }

}

From source file:org.apache.hadoop.hbase.migration.nineteen.regionserver.HStoreFile.java

/** 
 * Reads in an info file//from   ww w.j av  a  2 s . co m
 *
 * @param filesystem file system
 * @return The sequence id contained in the info file
 * @throws IOException
 */
public long loadInfo(final FileSystem filesystem) throws IOException {
    Path p = null;
    if (isReference()) {
        p = getInfoFilePath(reference.getEncodedRegionName(), this.reference.getFileId());
    } else {
        p = getInfoFilePath();
    }
    long length = filesystem.getFileStatus(p).getLen();
    boolean hasMoreThanSeqNum = length > (Byte.SIZE + Bytes.SIZEOF_LONG);
    DataInputStream in = new DataInputStream(filesystem.open(p));
    try {
        byte flag = in.readByte();
        if (flag == INFO_SEQ_NUM) {
            if (hasMoreThanSeqNum) {
                flag = in.readByte();
                if (flag == MAJOR_COMPACTION) {
                    this.majorCompaction = in.readBoolean();
                }
            }
            return in.readLong();
        }
        throw new IOException("Cannot process log file: " + p);
    } finally {
        in.close();
    }
}

From source file:com.adito.notification.Notifier.java

void loadFromDisk() throws IOException {
    File[] f = queueDirectory.listFiles(new FileFilter() {
        public boolean accept(File f) {
            return f.getName().endsWith(".msg");
        }/* w ww  . ja  va 2  s .  c o m*/
    });
    // TODO better error handling in parsing of message files. Report on
    // non-existant / unreadable directory
    if (f == null) {
        throw new IOException("Could not list queue directory " + queueDirectory.getAbsolutePath());
    }
    for (int i = 0; i < f.length; i++) {
        FileInputStream fin = new FileInputStream(f[i]);
        try {
            DataInputStream din = new DataInputStream(fin);
            long id = din.readLong();
            String sinkName = din.readUTF();
            messageId = Math.max(id, messageId);
            boolean urgent = din.readBoolean();
            String subject = din.readUTF();
            List<Recipient> recipientList = new ArrayList<Recipient>();
            while (true) {
                int recipientType = din.readInt();
                if (recipientType == Recipient.EOF) {
                    break;
                } else {
                    String recipientAlias = din.readUTF();
                    String realmName = din.readUTF();
                    Recipient recipient = new Recipient(recipientType, recipientAlias, realmName);
                    recipientList.add(recipient);
                }
            }
            Properties parameters = new Properties();
            while (true) {
                int parameterType = din.readInt();
                if (parameterType < 1) {
                    break;
                } else {
                    String key = din.readUTF();
                    String val = din.readUTF();
                    parameters.setProperty(key, val);
                }
            }
            String content = din.readUTF();
            String lastMessage = din.readUTF();
            Message msg = new Message(subject, content, urgent);
            msg.setId(id);
            msg.setRecipients(recipientList);
            msg.setSinkName(sinkName);
            msg.setLastMessage(lastMessage);
            queue(msg);
        } finally {
            fin.close();
        }
    }
}

From source file:com.igormaznitsa.jhexed.hexmap.HexFieldLayer.java

public HexFieldLayer(final InputStream in) throws IOException {
    final DataInputStream din = in instanceof DataInputStream ? (DataInputStream) in : new DataInputStream(in);
    this.name = din.readUTF();
    this.comments = din.readUTF();

    final int valuesNum = din.readShort() & 0xFFFF;
    for (int i = 0; i < valuesNum; i++) {
        final HexFieldValue value = HexFieldValue.readValue(in);
        value.setIndex(i);//from w  w  w . j  a  va 2 s. c o m
        this.values.add(value);
    }

    this.columns = din.readInt();
    this.rows = din.readInt();
    this.visible = din.readBoolean();

    final byte[] packedLayerData = new byte[din.readInt()];
    IOUtils.readFully(din, packedLayerData);
    this.array = Utils.unpackArray(packedLayerData);

    if (this.array.length != (this.columns * this.rows))
        throw new IOException("Wrong field size");
}

From source file:IntSort.java

public void readStream() {
    try {/* www .  j a va2s . c o m*/
        // Careful: Make sure this is big enough!
        // Better yet, test and reallocate if necessary      
        byte[] recData = new byte[50];

        // Read from the specified byte array
        ByteArrayInputStream strmBytes = new ByteArrayInputStream(recData);

        // Read Java data types from the above byte array
        DataInputStream strmDataType = new DataInputStream(strmBytes);

        if (rs.getNumRecords() > 0) {
            ComparatorInt comp = new ComparatorInt();

            int i = 1;
            RecordEnumeration re = rs.enumerateRecords(null, comp, false);
            while (re.hasNextElement()) {
                // Get data into the byte array          
                rs.getRecord(re.nextRecordId(), recData, 0);

                // Read back the data types      
                System.out.println("Record #" + i++);

                System.out.println("Name: " + strmDataType.readUTF());
                System.out.println("Dog: " + strmDataType.readBoolean());
                System.out.println("Rank: " + strmDataType.readInt());
                System.out.println("--------------------");

                // Reset so read starts at beginning of array 
                strmBytes.reset();
            }

            comp.compareIntClose();

            // Free enumerator
            re.destroy();
        }

        strmBytes.close();
        strmDataType.close();

    } catch (Exception e) {
        db(e.toString());
    }
}

From source file:com.chaosinmotion.securechat.messages.SCMessageQueue.java

/**
 *  Process a data packet from the back end notification service. A data
 *  packet response form the back end has the format:
 *
 *  first byte//from   w ww. j  a v a2  s .c  om
 *  0x20        Message
 *  0x21        Token response
 *  0x22        Login failure
 *
 *  Note login success is implicit; if login worked, we start receiving
 *  message notifications, starting with the backlog of stored messages
 *  waiting for us
 */

private void processDataPacket(byte[] data) {
    if (data.length == 0)
        return;

    if (data[0] == 0x20) {
        /*
         *  Process received message.
         */

        ByteArrayInputStream bais = new ByteArrayInputStream(data, 1, data.length - 1);
        DataInputStream dis = new DataInputStream(bais);

        try {
            boolean toflag = dis.readBoolean();
            int messageID = dis.readInt();
            int senderID = dis.readInt();
            String ts = dis.readUTF();
            String senderName = dis.readUTF();
            int messagelen = dis.readInt();
            byte[] message = new byte[messagelen];
            dis.read(message);

            dis.close();

            insertMessage(senderID, senderName, toflag, messageID, DateUtils.parseServerDate(ts), message);

        } catch (IOException e) {
            e.printStackTrace();
        }
    } else if (data[0] == 0x21) {
        /*
         * Received token; rest is string
         */

        try {
            String token = new String(data, 1, data.length - 1, "UTF-8");
            loginPhaseTwo(token);
        } catch (UnsupportedEncodingException e) {
            // SHould never happen
        }
    } else if (data[0] == 0x22) {
        /*
         *  Login failure. Close connection and start polling
         */

        closeConnection();
        startPolling("Login failure");
    }
}