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:org.obm.push.protocol.data.Base64ASTimeZoneDecoderImpl.java

private byte[] readBytes(ByteArrayInputStream byteArrayInputStream, int length) {
    byte[] bytes = new byte[length];
    for (int i = 0; i < length; i++) {
        bytes[i] = (byte) byteArrayInputStream.read();
    }//  w w  w.ja  v a2  s . c  o m
    return bytes;
}

From source file:corner.service.svn.HibernateObjectTest.java

@Test
public void testDecodeBase64() {
    byte[] bytes = base64.decode("dGVzdA==");

    ByteArrayInputStream input = new ByteArrayInputStream(bytes);

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    int ch = 0;/*from   w w w.j a  v a2s  . c  om*/

    try {
        while ((ch = input.read()) != -1) {
            out.write((char) ch);
        }
        input.close();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals("test", new String(out.toByteArray()));
}

From source file:org.candlepin.servlet.filter.logging.LoggingRequestWrapper.java

@Override
public ServletInputStream getInputStream() throws IOException {
    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body);
    ServletInputStream servletInputStream = new ServletInputStream() {
        public int read() throws IOException {
            return byteArrayInputStream.read();
        }//from   w  w w. j a  v  a  2 s  .  com
    };
    return servletInputStream;
}

From source file:net.gplatform.sudoor.server.security.model.MultipleReadRequestWrapper.java

@Override
public ServletInputStream getInputStream() throws IOException {
    prepareInputStream();//  w w w .ja v a2  s. c  om

    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bContent);
    ServletInputStream inputStream = new ServletInputStream() {
        public int read() throws IOException {
            return byteArrayInputStream.read();
        }
    };
    return inputStream;
}

From source file:org.candlepin.common.filter.TeeHttpServletRequest.java

@Override
public ServletInputStream getInputStream() throws IOException {
    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body);
    ServletInputStream servletInputStream = new ServletInputStream() {
        @Override/*from ww  w.j  a v  a2 s  .  c  om*/
        public int read() throws IOException {
            return byteArrayInputStream.read();
        }
    };
    return servletInputStream;
}

From source file:org.apache.nifi.provenance.AESProvenanceEventEncryptor.java

private EncryptionMetadata extractEncryptionMetadata(byte[] encryptedRecord)
        throws EncryptionException, IOException, ClassNotFoundException {
    if (encryptedRecord == null || encryptedRecord.length < MIN_METADATA_LENGTH) {
        throw new EncryptionException("The encrypted record is too short to contain the metadata");
    }//from  w  w w.  j  a  v  a2 s  .  co m

    // Skip the first byte (SENTINEL) and don't need to copy all the serialized record
    ByteArrayInputStream bais = new ByteArrayInputStream(encryptedRecord);
    bais.read();
    try (ObjectInputStream ois = new ObjectInputStream(bais)) {
        return (EncryptionMetadata) ois.readObject();
    }
}

From source file:org.ovirt.vdsmfake.servlet.CustomHttpServletRequestWrapper.java

@Override
public ServletInputStream getInputStream() throws IOException {
    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(inputStreamData);

    ServletInputStream inputStream = new ServletInputStream() {
        @Override/*www  . j  a v a2  s  .c o m*/
        public int read() throws IOException {
            return byteArrayInputStream.read();
        }
    };

    return inputStream;
}

From source file:com.arvato.thoroughly.filter.FilterRequestWrapper.java

@Override
public ServletInputStream getInputStream() throws IOException {

    final ByteArrayInputStream bais = new ByteArrayInputStream(body.getBytes(Charset.forName("UTF-8")));

    return new ServletInputStream() {

        @Override//  w  ww.  ja  v a  2 s  .c  o m
        public int read() throws IOException {
            return bais.read();
        }

        @Override
        public boolean isFinished() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean isReady() {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public void setReadListener(ReadListener arg0) {
            // TODO Auto-generated method stub

        }

    };
}

From source file:be.fedict.eid.idp.protocol.openid.StatelessServerAssociationStore.java

private Association loadFromHandle(String handle)
        throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException,
        BadPaddingException, IOException, InvalidAlgorithmParameterException {
    byte[] encodedHandle = Base64.decodeBase64(handle);
    if (null != this.macSecretKeySpec) {
        byte[] signature = new byte[32];
        System.arraycopy(encodedHandle, 0, signature, 0, 32);
        byte[] toBeSigned = new byte[encodedHandle.length - 32];
        System.arraycopy(encodedHandle, 32, toBeSigned, 0, encodedHandle.length - 32);
        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(this.macSecretKeySpec);
        byte[] actualSignature = mac.doFinal(toBeSigned);
        if (false == Arrays.equals(actualSignature, signature)) {
            return null;
        }/*from  w  ww.  j  ava 2s  .c o m*/
        encodedHandle = toBeSigned;
    }
    byte[] iv = new byte[16];
    System.arraycopy(encodedHandle, 0, iv, 0, iv.length);
    byte[] encodedData = Arrays.copyOfRange(encodedHandle, 16, encodedHandle.length);
    Cipher cipher = Cipher.getInstance(CIPHER_ALGO);
    IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
    cipher.init(Cipher.DECRYPT_MODE, this.secretKeySpec, ivParameterSpec);
    byte[] associationBytes = cipher.doFinal(encodedData);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(associationBytes);
    int typeByte = byteArrayInputStream.read();
    if (typeByte == 1) {
        byte[] macKeyBytes = new byte[160 / 8];
        byteArrayInputStream.read(macKeyBytes);
        DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
        long exp = dataInputStream.readLong();
        Date expDate = new Date(exp);
        return Association.createHmacSha1(handle, macKeyBytes, expDate);
    } else if (typeByte == 2) {
        byte[] macKeyBytes = new byte[256 / 8];
        byteArrayInputStream.read(macKeyBytes);
        DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
        long exp = dataInputStream.readLong();
        Date expDate = new Date(exp);
        return Association.createHmacSha256(handle, macKeyBytes, expDate);
    } else {
        return null;
    }
}

From source file:org.deegree.securityproxy.filter.RequestBodyWrapperTest.java

private ServletInputStream createServletStream() {
    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(TEST_CONTENT.getBytes());
    return new ServletInputStream() {

        @Override// w  ww.j av a 2 s.c o m
        public int read() throws IOException {
            return byteArrayInputStream.read();
        }
    };
}