List of usage examples for java.io DataInputStream readShort
public final short readShort() throws IOException
readShort
method of DataInput
. From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream fin = new FileInputStream("C:/Short.txt"); DataInputStream din = new DataInputStream(fin); short s = din.readShort(); System.out.println("short : " + s); din.close();/*from www. ja v a 2 s . com*/ }
From source file:Main.java
public static void main(String[] args) throws IOException { short[] s = { 12345, 12345 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (short j : s) { dos.writeShort(j);/* w w w. j a v a 2 s.co m*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { short k = dis.readShort(); System.out.print(k); } }
From source file:Main.java
public static void main(String[] args) throws IOException { short[] s = { 123, 234 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (short j : s) { dos.writeShort(j);// w ww. j a va 2 s . co m } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { short k = dis.readShort(); System.out.print(k); } }
From source file:MainClass.java
public static void main(String args[]) { try {// ww w. j a va2s . c om 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:Main.java
public static short readShort(DataInputStream is) throws IOException { return Short.reverseBytes(is.readShort()); }
From source file:Main.java
public static short byteArrayToShort(byte[] input) { try {//from w ww .ja v a2s.c o m ByteArrayInputStream bis = new ByteArrayInputStream(input); DataInputStream dis = new DataInputStream(bis); short numb = dis.readShort(); dis.close(); return numb; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:Main.java
protected static InetSocketAddress deserialiseAddress(DataInputStream is) throws IOException { byte[] bytes = deserialiseByteArray(is, 16); int port = is.readShort() & 0xffff; return (new InetSocketAddress(InetAddress.getByAddress(bytes), port)); }
From source file:org.apache.hadoop.hdfs.server.datanode.BlockMetadataHeader.java
/** * This reads all the fields till the beginning of checksum. * @return Metadata Header/*ww w . j a v a 2 s. c o m*/ * @throws IOException */ public static BlockMetadataHeader readHeader(DataInputStream in) throws IOException { return readHeader(in.readShort(), in); }
From source file:HexUtil.java
/** * Read a (reasonably short) BigInteger from a DataInputStream * @param dis the stream to read from//from w ww .j ava 2s . c o m * @return a BigInteger */ public static BigInteger readBigInteger(DataInputStream dis) throws IOException { short i = dis.readShort(); if (i < 0) throw new IOException("Invalid BigInteger length: " + i); byte[] buf = new byte[i]; dis.readFully(buf); return new BigInteger(1, buf); }
From source file:Main.java
protected static int deserialiseLength(DataInputStream is, int max_length) throws IOException { int len;//from ww w .j a va 2 s .com if (max_length < 256) { len = is.readByte() & 0xff; } else if (max_length < 65536) { len = is.readShort() & 0xffff; } else { len = is.readInt(); } if (len > max_length) { throw (new IOException("Invalid DHT data length: max=" + max_length + ",actual=" + len)); } return (len); }