Java 8 ByteArrayInputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ByteArrayInputStream class.

This code example shows how to use the following methods:
    public byte[] asBytes() { 
        return fileItem.get(); 
    } 
 
    public InputStream asStream() { 
        return new ByteArrayInputStream(fileItem.get()); 
    } 
 
    public String getContentType() { 
        return fileItem.getContentType(); 
    } 
 
    public String getFileName() { 
        return fileItem.getName(); 
    } 
 
    public String getFieldName() { 
        return fileItem.getFieldName(); 
    } 
 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(bos);
        ByteBufferUtil.writeWithLength(bb, out);
        ByteBufferUtil.writeWithShortLength(bb, out);
 
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
        assert bb.equals(ByteBufferUtil.readWithLength(in));
        assert bb.equals(ByteBufferUtil.readWithShortLength(in));
    } 
 
    @Test 
    public void testInputStream() throws IOException 
    { 
        ByteBuffer bb = ByteBuffer.allocate(13);
        bb.putInt(255);
        bb.put((byte) -3);
        bb.putLong(42L);
        bb.clear();
 
        DataInputStream in = new DataInputStream(ByteBufferUtil.inputStream(bb));
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close, mark
  } 
 
  @Test 
  public void testSkipFully() throws IOException { 
    byte inArray[] = new byte[] {0, 1, 2, 3, 4};
    ByteArrayInputStream in = new ByteArrayInputStream(inArray);
    try { 
      in.mark(inArray.length);
      IOUtils.skipFully(in, 2);
      IOUtils.skipFully(in, 2);
      try { 
        IOUtils.skipFully(in, 2);
        fail("expected to get a PrematureEOFException"); 
      } catch (EOFException e) {
        assertEquals(e.getMessage(), "Premature EOF from inputStream " +
            "after skipping 1 byte(s)."); 
      } 
      in.reset();
      try { 
        IOUtils.skipFully(in, 20);

10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    TypedBytesWritable tbw = new TypedBytesWritable();
    tbw.setValue(12345);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutput dout = new DataOutputStream(baos);
    tbw.write(dout);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    DataInput din = new DataInputStream(bais);
    TypedBytesWritable readTbw = new TypedBytesWritable();
    readTbw.readFields(din);
    assertEquals(tbw, readTbw);
  } 
 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close
    public Object decodeObject(final byte[] in) throws IOException {
        Object obj = null;
        ByteArrayInputStream bais = null;
        HessianInput input = null;
        try { 
            bais = new ByteArrayInputStream(in);
            input = new HessianInput(bais);
            input.startReply();
            obj = input.readObject();
            input.completeReply();
        } 
        catch (final IOException ex) {
            throw ex;
        } 
        catch (final Throwable e) {
            this.logger.error("Failed to decode object.", e);
        } 
        finally { 
            if (input != null) {
                try { 

9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close, mark, reset
  } 
 
  @Test
  public void testSkipFully() throws IOException {
    byte inArray[] = new byte[] {0, 1, 2, 3, 4};
    ByteArrayInputStream in = new ByteArrayInputStream(inArray);
    try { 
      in.mark(inArray.length);
      IOUtils.skipFully(in, 2);
      IOUtils.skipFully(in, 2);
      try { 
        IOUtils.skipFully(in, 2);
        fail("expected to get a PrematureEOFException"); 
      } catch (EOFException e) {
        assertEquals("Premature EOF from inputStream " + 
                "after skipping 1 byte(s).",e.getMessage());
      } 
      in.reset();
      try { 
        IOUtils.skipFully(in, 20);

9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
      } 
       
      MultiFileSplit readSplit = new MultiFileSplit();
      ByteArrayInputStream bis = null;
      try { 
        bis = new ByteArrayInputStream(result);
        readSplit.readFields(new DataInputStream(bis));
      } finally { 
        IOUtils.closeStream(bis);
      } 
       
      assertTrue(split.getLength() != 0);
      assertEquals(split.getLength(), readSplit.getLength());
      assertTrue(Arrays.equals(split.getPaths(), readSplit.getPaths()));
      assertTrue(Arrays.equals(split.getLengths(), readSplit.getLengths()));
      System.out.println(split.toString());
    } 
     
    /** 
     * test method getLocations 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		verify(ps).setBytes(1, content);
	} 
 
	@Test
	public void testSetBlobAsBinaryStream() throws SQLException, IOException {
		InputStream bis = new ByteArrayInputStream("testContent".getBytes());
		lobCreator.setBlobAsBinaryStream(ps, 1, bis, 11);
		verify(ps).setBinaryStream(1, bis, 11);
	} 
 
	@Test
	public void testSetBlobAsBinaryStreamWithoutLength() throws SQLException, IOException {
		InputStream bis = new ByteArrayInputStream("testContent".getBytes());
		lobCreator.setBlobAsBinaryStream(ps, 1, bis, -1);
		verify(ps).setBinaryStream(1, bis);
	} 
 
	@Test
	public void testSetClobAsString() throws SQLException, IOException {
		String content = "testContent";
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
	@Override 
	public Properties convert(String source) {
		try { 
			Properties props = new Properties();
			// Must use the ISO-8859-1 encoding because Properties.load(stream) expects it. 
			props.load(new ByteArrayInputStream(source.getBytes("ISO-8859-1")));
			return props;
		} 
		catch (Exception ex) {
			// Should never happen. 
			throw new IllegalArgumentException("Failed to parse [" + source + "] into Properties", ex);
		} 
	} 
 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
    if (outStream == null) {
      throw new FileNotFoundException(String.format("unknown file[%s]", filename));
    } 
 
    return new ByteArrayInputStream(outStream.toByteArray());
  } 
 
  @Override 
  public void cleanup() throws IOException 
  { 
    outStreams.clear();
  } 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 ByteArrayInputStream Questions & Answers:

See Code Examples for Java 8 ByteArrayInputStream Methods: