Example usage for java.io InputStream read

List of usage examples for java.io InputStream read

Introduction

In this page you can find the example usage for java.io InputStream read.

Prototype

public abstract int read() throws IOException;

Source Link

Document

Reads the next byte of data from the input stream.

Usage

From source file:Main.java

public static byte[] readCLenData(InputStream is) throws IOException {
    int len = is.read();
    if (len <= 0) {
        return null;
    }/*www.  j  a v  a2  s .  c o  m*/

    return readBytes(is, len);
}

From source file:Main.java

public static byte readByte(final InputStream stream) throws IOException {
    return (byte) (stream.read() & 0xFF);
}

From source file:Main.java

/**
 * Reads the next byte from the input stream.
 * @param input  the stream//from  w  ww  . j  a  va 2  s  . c  om
 * @return the byte
 * @throws IOException if the end of file is reached
 */
private static int read(InputStream input) throws IOException {
    int value = input.read();

    if (-1 == value) {
        throw new EOFException("Unexpected EOF reached");
    }

    return value;
}

From source file:com.orange.ClientWithResponseHandler.java

private static void mRead(HttpEntity entity) throws IOException {
    InputStream instream = entity.getContent();
    try {/*ww w  . j a va2  s. c o  m*/
        instream.read();
        // do something useful with the response
    } catch (IOException ex) {
        // In case of an IOException the connection will be released
        // back to the connection manager automatically
        throw ex;
    } finally {
        // Closing the input stream will trigger connection release
        instream.close();
    }
}

From source file:Main.java

/**
 * Returns true if files are same and false value if the files are different.
 * This function is very slow, so it will probably need a rewrite.
 * @param fileIS1 Input stream associated with the first file
 * @param fileIS2 Input stream associated with the second file
 * @return True if the files are the same, false otherwise.
 * @throws IOException if an error is encountered.
 *//*w w w .  j a  v  a 2 s.c  o  m*/
public static boolean sameContents(InputStream fileIS1, InputStream fileIS2) throws IOException {
    int b1 = fileIS1.read();
    int b2 = fileIS2.read();
    while ((b1 != -1) && (b2 != -1)) {
        if (b1 != b2) {
            return false;
        }
        b1 = fileIS1.read();
        b2 = fileIS2.read();
    }
    return b1 == b2;
}

From source file:Main.java

static public final String readPassword(OutputStream out, InputStream in) throws IOException {
    int rd = in.read();
    if (rd == -1)
        return null;
    byte r = (byte) rd;
    int i = 0;/*  w w w.  java2s.  c o m*/
    int l = 50;
    byte[] buf = new byte[l];
    while (r != '\n') {
        if (i >= l - 1) {
            l += 50;
            byte[] old = buf;
            buf = new byte[l];
            System.arraycopy(old, 0, buf, 0, old.length);
        }
        if (r != '\r') {
            buf[i++] = r;
            out.write('\b');
            out.write('*');
            out.flush();
        }
        rd = in.read();
        if (rd == -1)
            break;
        r = (byte) rd;
    }
    return new String(buf, 0, i);
}

From source file:Main.java

private static String getResponseMessage(InputStream inputStream, HttpURLConnection connection)
        throws UnsupportedEncodingException, IOException {
    String responseMessage = null;
    StringBuffer sb = new StringBuffer();
    InputStream dis = connection.getInputStream();
    int chr;/*from w w w  . j av a  2 s  .  c om*/
    while ((chr = dis.read()) != -1) {
        sb.append((char) chr);
    }
    if (sb != null) {
        responseMessage = sb.toString();
    }
    return responseMessage;
}

From source file:Main.java

public static void write(InputStream in, OutputStream out) throws Throwable {
    int read = 0;
    while ((read = in.read()) != -1) {
        out.write(read);/*from  w w  w . j ava  2 s. co m*/
    }
    in.close();
    out.close();
    out.flush();
}

From source file:Main.java

public static void write(InputStream in, OutputStream out) throws IOException {
    int read = 0;
    while ((read = in.read()) != -1) {
        out.write(read);/*from   w w  w. j a  v a  2  s . co m*/
    }
    in.close();
    out.close();
    out.flush();
}

From source file:Main.java

public static int parseLength(InputStream input) throws IOException {
    int complexTag = 0;
    int nextByte = input.read();

    boolean isComplexLength = (nextByte & 0x80) > 0;
    if (isComplexLength) {
        int bytesCount = nextByte & 0x7f;
        for (int i = 0; i < bytesCount; i++) {
            complexTag <<= 8;//from   w w w  .  j av a  2 s.  co m
            complexTag |= input.read();
        }
        return complexTag;
    } else {
        return nextByte & 0x7f;
    }
}