List of usage examples for java.io InputStream read
public abstract int read() throws IOException;
From source file:Main.java
public static final int readInt(InputStream i) throws IOException, EOFException { InputStream in = i; int ch1 = in.read(); int ch2 = in.read(); int ch3 = in.read(); int ch4 = in.read(); if ((ch1 | ch2 | ch3 | ch4) < 0) throw new EOFException(); return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0)); }
From source file:Main.java
public static int readUnsignedInt24(InputStream in) throws IOException { return ((in.read() & 0xff) << 16) | ((in.read() & 0xff) << 8) | (in.read() & 0xff); }
From source file:Main.java
public static int readUnsignedInt16(InputStream in) throws IOException { return ((in.read() & 0xff) << 8) | (in.read() & 0xff); }
From source file:Main.java
public static int readUnsignedInt32(InputStream in) throws IOException { return ((in.read() & 0xff) << 24) | ((in.read() & 0xff) << 16) | ((in.read() & 0xff) << 8) | (in.read() & 0xff);/*from ww w . ja va2 s.c om*/ }
From source file:Main.java
public static String inputStreamToString(InputStream inputStream) throws IOException { StringWriter sw = new StringWriter(); int c;//from w ww.j av a 2 s . com InputStream in = inputStream; while ((c = in.read()) != -1) { sw.write(c); } return sw.toString(); }
From source file:Main.java
public static long getCRC32(InputStream in) throws IOException { Checksum cs = new CRC32(); for (int b = in.read(); b != -1; b = in.read()) { cs.update(b);//ww w . j a v a 2s . c om } return cs.getValue(); }
From source file:Main.java
public static final int Read1(InputStream in) { try {//from ww w .ja v a 2 s . com return ((int) in.read() & 0xff); } catch (IOException e) { return -1; } }
From source file:Main.java
public static double readDouble(InputStream in) throws IOException { long bits = ((long) (in.read() & 0xff) << 56) | ((long) (in.read() & 0xff) << 48) | ((long) (in.read() & 0xff) << 40) | ((long) (in.read() & 0xff) << 32) | ((in.read() & 0xff) << 24) | ((in.read() & 0xff) << 16) | ((in.read() & 0xff) << 8) | (in.read() & 0xff); return Double.longBitsToDouble(bits); }
From source file:Count.java
public static void countChars(InputStream in) throws IOException { int count = 0; while (in.read() != -1) count++;// w w w. ja v a 2 s . c om System.out.println("Counted " + count + " chars."); }
From source file:Main.java
/** * Simple wrapper around {@link InputStream#read()} that throws EOFException * instead of returning -1./*from w ww . ja va2s . co m*/ */ public static int read(InputStream is) throws IOException { int b = is.read(); if (b == -1) { throw new EOFException(); } return b; }