InputStream available - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for InputStream available method.

This code example shows how to use the following methods:available, mark, markSupported, read, reset
     * 
     * @param t            the instance of the JAXB type. 
     * @param mediaType    the meida type. 
     * @param c            the character set to serialize characters to. 
     * @param m            the marshaller to marshaller the instance of the JAXB type. 
     * @param entityStream the output stream to marshal to. 
     * @throws javax.xml.bind.JAXBException 
     */ 
    protected void writeTo(Object t, MediaType mediaType, Charset c,
                           Marshaller m, OutputStream entityStream)
            throws JAXBException { 
        m.marshal(t, entityStream);
    } 
} 

8
CodeRank
This code example shows how to use the following methods:available, reset
	@Override 
	public void prepareForReading(InputStream stream) {
		sourceSize = -1;
		if ((stream instanceof ByteArrayInputStream)) {
			try { 
				sourceSize = stream.available();
			} catch (IOException e) {}
		} 
		 
		if (log.isDebugEnabled()) { 
			saveSourceMessage(stream);
		} 
		 
		super.prepareForReading(stream);
	} 
 
	/** 
	 * Add DEBUG logging for messages that fail to be decoded 
	 */ 
	@Override 

8
CodeRank
This code example shows how to use the following methods:available, read
 
	InputStream file = null;
 
	public void testByte() throws Exception { 
		file = getFile("D:\\gfile\\object");
		byte[] content = new byte[file.available()];
		file.read(content);
		ByteBuffer buffer = ByteBuffer.wrap(content);
		ObObj obj = new ObObj();
		obj.deserialize(buffer);
		Assert.assertEquals(9871345, (long) (Long) obj.getValue());
		obj.deserialize(buffer);
		Assert.assertEquals("Hello", obj.getValue());
		obj.deserialize(buffer);
		Assert.assertEquals(null, obj.getValue());
		obj.deserialize(buffer);
		Assert.assertEquals(59.16f, obj.getValue());
		obj.deserialize(buffer);
		Assert.assertEquals(59.167d, obj.getValue());
		obj.deserialize(buffer);
7
CodeRank
This code example shows how to use the following methods:available
            _toGo = max;
        } 
 
        public int available() 
            throws IOException { 
            return _in.available();
        } 
 
        public int read() 
            throws IOException { 
 
            if ( _toGo <= 0 )
                return -1; 
 
            int val = _in.read();
            _toGo--;
 
            return val;
        } 
 
7
CodeRank
This code example shows how to use the following methods:available, close, read
        return readInputStreamFully(is);
    } 
 
    protected byte[] readInputStreamFully(InputStream is) {
        try { 
            byte[] buffer = new byte[is.available()];
            is.read(buffer);
            is.close();
            return buffer;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } 
    } 
 
    private void addStreamItemsToRawContact(long rawContactId, String accountType,
            String accountName) {
        ArrayList<ContentProviderOperation> ops = Lists.newArrayList();
 
        // Add from 1-5 stream items. 
        int itemsToAdd = randInt(5) + 1;
7
CodeRank
This code example shows how to use the following methods:available
    } 
 
    @Override 
    public final int available() throws IOException {
        InputStream stream = currentStream();
        return stream == null ? 0 : stream.available();
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:available
   * @param in The input stream to be compressed. 
   * @throws IOException 
   */ 
  protected CompressionInputStream(InputStream in) throws IOException {
    if (!(in instanceof Seekable) || !(in instanceof PositionedReadable)) {
        this.maxAvailableData = in.available();
    } 
    this.in = in;
  } 
 
  @Override 
  public void close() throws IOException { 
    in.close();
  } 
   
  /** 
   * Read bytes from the stream. 
   * Made abstract to prevent leakage to underlying stream. 
   */ 
  @Override 
7
CodeRank
This code example shows how to use the following methods:available, read
  { 
    final byte[] bytes = new byte[] {1,2,3,4};
    final ByteString bs = ByteString.copy(bytes);
 
    final InputStream in = bs.asInputStream();
    Assert.assertEquals(bytes.length, in.available());
 
    final byte[] actual = new byte[bytes.length];
    Assert.assertEquals(bytes.length, in.read(actual));
 
    Assert.assertEquals(bytes, actual);
  } 
 
  @Test 
  public void testEquals() 
  { 
    Assert.assertEquals(ByteString.copy(new byte[] {1,2,3,4}),
                        ByteString.copy(new byte[] {1,2,3,4})); 
    Assert.assertFalse(ByteString.copy(new byte[] {1,2,3,4}).equals(
                       ByteString.copy(new byte[] {5,6,7,8}))); 
7
CodeRank
This code example shows how to use the following methods:available, read
        try { 
            IOUtils.copyBytes(is, process.getOutputStream(), config);
        } catch (IOException ignored) {
            try { 
                InputStream stderr = process.getErrorStream();
                if (stderr.available() > 0) {
                    byte[] msg = new byte[stderr.available()];
                    stderr.read(msg);
                    System.err.println(new String(msg));
                } 
            } catch (IOException e) {
                System.err.println(e);
            } 
        } 
 
        System.err.println("fsdis copy done");
    } 
} 
7
CodeRank
This code example shows how to use the following methods:available
    private void fillPacket() throws IOException 
    { 
        if (_closed)
            return; 
 
        if (_gotFirst||_in.available()==0)
            _getBodyChunk.write(_out);
        _gotFirst=true;
 
        // read packet 
        if (!_packet.read(_in))
            throw new IOException("EOF");
 
        if (_packet.unconsumedData()<=0)
            _closed=true;
        else if (_packet.getInt()>_packet.getBufferSize())
            throw new IOException("AJP Protocol error");
    } 
 
    /* ------------------------------------------------------------ */ 
7
CodeRank

Related InputStream available Questions & Answers:

available Method Overview
Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.
See Code Examples for other Java 8 InputStream Methods: