Example usage for java.io ByteArrayInputStream read

List of usage examples for java.io ByteArrayInputStream read

Introduction

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

Prototype

public synchronized int read() 

Source Link

Document

Reads the next byte of data from this input stream.

Usage

From source file:at.jku.rdfstats.hist.builder.HistogramCodec.java

protected static long readLong(ByteArrayInputStream stream) {
    long l = 0;//  w  w  w  .j ava 2s . c  om
    for (int i = 56; i >= 0; i -= 8) {
        int next = stream.read();
        if (next >= 0)
            l |= (long) next << i;
        else
            break;
    }
    return l;
}

From source file:at.jku.rdfstats.hist.builder.HistogramCodec.java

protected static int readInt(ByteArrayInputStream stream) {
    int ival = 0;
    for (int i = 24; i >= 0; i -= 8) {
        int next = stream.read();
        if (next >= 0)
            ival |= next << i;/*from  w w  w. j  a  v  a2  s . com*/
        else
            break;
    }
    return ival;
}

From source file:hudson.plugins.jobConfigHistory.TUtils.java

static ServletInputStream createServletInputStreamFromMultiPartFormData(final String boundary) {
    final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"timestamp1\"\r\n\r\n"
            + "2014-02-05_10-42-37\r\n" + "--" + boundary + "\r\n"
            + "Content-Disposition: form-data; name=\"timestamp2\"\r\n\r\n" + "2014-03-12_11-02-12\r\n" + "--"
            + boundary + "\r\n" + "Content-Disposition: form-data; name=\"name\"\r\n\r\n" + "foo\r\n" + "--"
            + boundary + "--\r\n";
    final ByteArrayInputStream bodyByteStream = new ByteArrayInputStream(body.getBytes());
    return new ServletInputStream() {
        @Override/*from   w  w w  .j  a va 2s . c o  m*/
        public int read() throws IOException {
            return bodyByteStream.read();
        }
    };
}

From source file:org.jopenray.server.thinclient.DisplayReaderThread.java

public static int readInt32(ByteArrayInputStream in) {
    int a = in.read();
    int b = in.read();
    int c = in.read();
    int d = in.read();
    if (a < 0 || b < 0 || c < 0 || d < 0) {
        throw new IllegalStateException("Unexpected end of stream");
    }//from   w  ww. j  a  va  2s  .  c o m
    return a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
}

From source file:adams.core.io.GzipUtils.java

/**
 * Compresses the specified bytes using gzip.
 *
 * @param input   the bytes to compress//from   w ww .j a v a  2s.  c  om
 * @return      the compressed bytes, null in case of error
 */
public static byte[] compress(byte[] input) {
    ByteArrayInputStream bis;
    ByteArrayOutputStream bos;
    GZIPOutputStream gos;
    int i;

    try {
        bis = new ByteArrayInputStream(input);
        bos = new ByteArrayOutputStream();
        gos = new GZIPOutputStream(bos);
        while ((i = bis.read()) != -1)
            gos.write(i);
        gos.finish();
        return bos.toByteArray();
    } catch (Exception e) {
        System.err.println("Failed to compress bytes!");
        e.printStackTrace();
        return null;
    }
}

From source file:org.jopenray.client.RendererListener.java

public static int readInt16(ByteArrayInputStream in) {
    int a = in.read();
    int b = in.read();
    if (a < 0 || b < 0) {
        throw new IllegalStateException("Unexpected end of stream");
    }//from   ww w  . j a  va 2s .  c  o m
    return a * 256 + b;
}

From source file:org.jopenray.client.RendererListener.java

public static int readInt32(ByteArrayInputStream in) {
    int a = in.read();
    int b = in.read();
    int c = in.read();
    int d = in.read();
    if (a < 0 || b < 0 || c < 0 || d < 0) {
        throw new IllegalStateException("Unexpected end of stream");
    }//from ww  w  .  j  a  va  2 s .  com
    return a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;

}

From source file:org.jopenray.client.RendererListener.java

public static Color readColor(ByteArrayInputStream in) {
    return new Color(in.read(), in.read(), in.read(), in.read());
}

From source file:UploadUtils.PomfUpload.java

/**
 * Send the file to Uguu.//ww w.j  a  va 2  s. c  om
 * @param b the contents of the file in a byte array
 * @param conn the connection to use
 * @throws java.IOException during writing to output stream
 */
private static void sendFile(byte[] b, HttpURLConnection conn) throws IOException {
    System.out.println("entered sendfile");
    String introline = "------" + boundary;
    String padder = String.format("Content-Disposition: form-data; name=\"files[]\"; filename=\"" + filename
            + "." + extension + "\"\r\nContent-type: " + tmpfiletype + "\r\n");
    String outroline = "------" + boundary + "--";

    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    DataOutputStream outstream;
    try {
        outstream = new DataOutputStream(conn.getOutputStream());
        outstream.writeBytes(introline);
        outstream.writeBytes("\r\n");
        outstream.writeBytes(padder);
        outstream.writeBytes("\r\n");

        int i;
        while ((i = bais.read()) > -1) {
            outstream.write(i);

        }
        bais.close();

        outstream.writeBytes("\r\n");
        outstream.writeBytes("\r\n");
        outstream.writeBytes(outroline);
        outstream.flush();
        outstream.close();
    } catch (IOException ex) {
        if (ex instanceof SSLHandshakeException) {
            ex.printStackTrace();
        } else {
            throw ex;
        }
    }
}

From source file:com.github.devnied.emvnfccard.utils.TlvUtil.java

public static int readTagLength(final ByteArrayInputStream stream) {
    // Find LENGTH bytes
    int length;/*from   w ww  .  j a va 2  s  . com*/
    int tmpLength = stream.read();

    if (tmpLength < 0) {
        throw new TlvException("Negative length: " + tmpLength);
    }

    if (tmpLength <= 127) { // 0111 1111
        // short length form
        length = tmpLength;
    } else if (tmpLength == 128) { // 1000 0000
        // length identifies indefinite form, will be set later
        // indefinite form is not specified in ISO7816-4, but we include it here for completeness
        length = tmpLength;
    } else {
        // long length form
        int numberOfLengthOctets = tmpLength & 127; // turn off 8th bit
        tmpLength = 0;
        for (int i = 0; i < numberOfLengthOctets; i++) {
            int nextLengthOctet = stream.read();
            if (nextLengthOctet < 0) {
                throw new TlvException("EOS when reading length bytes");
            }
            tmpLength <<= 8;
            tmpLength |= nextLengthOctet;
        }
        length = tmpLength;
    }
    return length;
}