List of usage examples for java.io DataInputStream readBoolean
public final boolean readBoolean() throws IOException
readBoolean
method of DataInput
. From source file:Main.java
public static void main(String[] args) throws IOException { byte[] buf = { 1, 2, 3, 4, 5 }; InputStream is = new ByteArrayInputStream(buf); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { System.out.println(dis.readBoolean()); }//w w w. j av a2s . c om }
From source file:MainClass.java
public static void main(String args[]) { try {//www . j a va2 s . co m FileInputStream fis = new FileInputStream("fileName.dat"); // Create a data input stream DataInputStream dis = new DataInputStream(fis); // Read and display data System.out.println(dis.readBoolean()); System.out.println(dis.readByte()); System.out.println(dis.readChar()); System.out.println(dis.readDouble()); System.out.println(dis.readFloat()); System.out.println(dis.readInt()); System.out.println(dis.readLong()); System.out.println(dis.readShort()); // Close file input stream fis.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:DataIODemo.java
public static void main(String args[]) throws IOException { FileOutputStream fout = new FileOutputStream("Test.dat"); DataOutputStream out = new DataOutputStream(fout); out.writeDouble(98.6);//from www .ja v a2s. c om out.writeInt(1000); out.writeBoolean(true); out.close(); FileInputStream fin = new FileInputStream("Test.dat"); DataInputStream in = new DataInputStream(fin); double d = in.readDouble(); int i = in.readInt(); boolean b = in.readBoolean(); System.out.println("Here are the values: " + d + " " + i + " " + b); in.close(); }
From source file:edu.msu.cme.rdp.taxatree.TreeBuilder.java
public static void main(String[] args) throws IOException { if (args.length != 3) { System.err.println("USAGE: TreeBuilder <idmapping> <merges.bin> <newick_out>"); return;// w w w. ja va2 s. c om } IdMapping<Integer> idMapping = IdMapping.fromFile(new File(args[0])); DataInputStream mergeStream = new DataInputStream(new BufferedInputStream(new FileInputStream(args[1]))); TaxonHolder lastMerged = null; int taxid = 0; final Map<Integer, Double> distMap = new HashMap(); Map<Integer, TaxonHolder> taxonMap = new HashMap(); try { while (true) { if (mergeStream.readBoolean()) { // Singleton int cid = mergeStream.readInt(); int intId = mergeStream.readInt(); TaxonHolder<Taxon> holder; List<String> seqids = idMapping.getIds(intId); if (seqids.size() == 1) { holder = new TaxonHolder(new Taxon(taxid++, seqids.get(0), "")); } else { holder = new TaxonHolder(new Taxon(taxid++, "", "")); for (String seqid : seqids) { int id = taxid++; distMap.put(id, 0.0); TaxonHolder th = new TaxonHolder(new Taxon(id, seqid, "")); th.setParent(holder); holder.addChild(th); } } lastMerged = holder; taxonMap.put(cid, holder); } else { int ci = mergeStream.readInt(); int cj = mergeStream.readInt(); int ck = mergeStream.readInt(); double dist = (double) mergeStream.readInt() / DistanceCalculator.MULTIPLIER; TaxonHolder holder = new TaxonHolder(new Taxon(taxid++, "", "")); taxonMap.put(ck, holder); holder.addChild(taxonMap.get(ci)); taxonMap.get(ci).setParent(holder); distMap.put(ci, dist); holder.addChild(taxonMap.get(cj)); taxonMap.get(cj).setParent(holder); distMap.put(cj, dist); lastMerged = holder; } } } catch (EOFException e) { } if (lastMerged == null) { throw new IOException("No merges in file"); } PrintStream newickTreeOut = new PrintStream(new File(args[2])); NewickPrintVisitor visitor = new NewickPrintVisitor(newickTreeOut, false, new NewickDistanceFactory() { public float getDistance(int i) { return distMap.get(i).floatValue(); } }); lastMerged.biDirectionDepthFirst(visitor); newickTreeOut.close(); }
From source file:Main.java
public static boolean readBoolean(DataInputStream is) throws IOException { return is.readBoolean(); }
From source file:Main.java
public static boolean readBool(DataInputStream in) throws IOException { return in.readBoolean(); }
From source file:com.opensoc.json.serialization.JSONDecoderHelper.java
public static Boolean getBoolean(DataInputStream data) throws IOException { return data.readBoolean(); }
From source file:com.atilika.kuromoji.trie.DoubleArrayTrie.java
/** * Load Stored data/* www . j a v a 2s. co m*/ * * @param input input stream to read the double array trie from * @return double array trie, not null * @throws IOException if an IO error occured during reading the double array trie */ public static DoubleArrayTrie read(InputStream input) throws IOException { DoubleArrayTrie trie = new DoubleArrayTrie(); DataInputStream dis = new DataInputStream(new BufferedInputStream(input)); trie.compact = dis.readBoolean(); int baseCheckSize = dis.readInt(); // Read size of baseArr and checkArr int tailSize = dis.readInt(); // Read size of tailArr ReadableByteChannel channel = Channels.newChannel(dis); ByteBuffer tmpBaseBuffer = ByteBuffer.allocate(baseCheckSize * 4); channel.read(tmpBaseBuffer); tmpBaseBuffer.rewind(); trie.baseBuffer = tmpBaseBuffer.asIntBuffer(); ByteBuffer tmpCheckBuffer = ByteBuffer.allocate(baseCheckSize * 4); channel.read(tmpCheckBuffer); tmpCheckBuffer.rewind(); trie.checkBuffer = tmpCheckBuffer.asIntBuffer(); ByteBuffer tmpTailBuffer = ByteBuffer.allocate(tailSize * 2); channel.read(tmpTailBuffer); tmpTailBuffer.rewind(); trie.tailBuffer = tmpTailBuffer.asCharBuffer(); input.close(); return trie; }
From source file:org.apache.jackrabbit.core.persistence.util.Serializer.java
/** * Deserializes a <code>PropertyState</code> object from the given binary * <code>stream</code>. Binary values are retrieved from the specified * <code>BLOBStore</code>.//from w w w .ja va2s . co m * * @param state <code>state</code> to deserialize * @param stream the stream where the <code>state</code> should be * deserialized from * @param blobStore handler for BLOB data * @throws Exception if an error occurs during the deserialization * @see #serialize(PropertyState, OutputStream, BLOBStore) */ public static void deserialize(PropertyState state, InputStream stream, BLOBStore blobStore) throws Exception { DataInputStream in = new DataInputStream(stream); // type int type = in.readInt(); state.setType(type); // multiValued boolean multiValued = in.readBoolean(); state.setMultiValued(multiValued); // definitionId in.readUTF(); // modCount short modCount = in.readShort(); state.setModCount(modCount); // values int count = in.readInt(); // count InternalValue[] values = new InternalValue[count]; for (int i = 0; i < count; i++) { InternalValue val; if (type == PropertyType.BINARY) { String s = in.readUTF(); // value (i.e. blobId) // special handling required for binary value: // the value stores the id of the BLOB data // in the BLOB store if (blobStore instanceof ResourceBasedBLOBStore) { // optimization: if the BLOB store is resource-based // retrieve the resource directly rather than having // to read the BLOB from an input stream FileSystemResource fsRes = ((ResourceBasedBLOBStore) blobStore).getResource(s); val = InternalValue.create(fsRes); } else { InputStream is = blobStore.get(s); try { val = InternalValue.create(is); } finally { try { is.close(); } catch (IOException e) { // ignore } } } } else { /** * because writeUTF(String) has a size limit of 65k, * Strings are serialized as <length><byte[]> */ //s = in.readUTF(); // value int len = in.readInt(); // lenght of byte[] byte[] bytes = new byte[len]; in.readFully(bytes); // byte[] String s = new String(bytes, ENCODING); val = InternalValue.valueOf(s, type); } values[i] = val; } state.setValues(values); }
From source file:RealFunctionValidation.java
public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out, final Class<?> type) throws IOException { if (!type.isPrimitive()) { throw new IllegalArgumentException("type must be primitive"); }/* w w w . ja v a2 s . c om*/ if (type.equals(Boolean.TYPE)) { final boolean x = in.readBoolean(); out.writeBoolean(x); return Boolean.valueOf(x); } else if (type.equals(Byte.TYPE)) { final byte x = in.readByte(); out.writeByte(x); return Byte.valueOf(x); } else if (type.equals(Character.TYPE)) { final char x = in.readChar(); out.writeChar(x); return Character.valueOf(x); } else if (type.equals(Double.TYPE)) { final double x = in.readDouble(); out.writeDouble(x); return Double.valueOf(x); } else if (type.equals(Float.TYPE)) { final float x = in.readFloat(); out.writeFloat(x); return Float.valueOf(x); } else if (type.equals(Integer.TYPE)) { final int x = in.readInt(); out.writeInt(x); return Integer.valueOf(x); } else if (type.equals(Long.TYPE)) { final long x = in.readLong(); out.writeLong(x); return Long.valueOf(x); } else if (type.equals(Short.TYPE)) { final short x = in.readShort(); out.writeShort(x); return Short.valueOf(x); } else { // This should never occur. throw new IllegalStateException(); } }