Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.io;
 
Byte Buffer interface. This is a byte buffer that is designed to work like a FIFO for bytes. Puts and Gets operate on different pointers into the buffer and the valid _content of the buffer is always between the getIndex and the putIndex. This buffer interface is designed to be similar, but not dependent on the java.nio buffers, which may be used to back an implementation of this Buffer. The main difference is that NIO buffer after a put have their valid _content before the position and a flip is required to access that data. For this buffer it is always true that: markValue <= getIndex <= putIndex <= capacity

Version:
1.0
 
 public interface Buffer extends Cloneable
 {
     public final static int 
       IMMUTABLE=0,  // neither indexes or contexts can be changed
       READONLY=1,   // indexes may be changed, but not content
       READWRITE=2;  // anything can be changed
     public final boolean VOLATILE=true;     // The buffer may change outside of current scope.
     public final boolean NON_VOLATILE=false;

    
Get the underlying array, if one exists.

Returns:
a byte[] backing this buffer or null if none exists.
 
     byte[] array();
    
    

Returns:
a byte[] value of the bytes from the getIndex to the putIndex.
 
     byte[] asArray();
    
    
Get the underlying buffer. If this buffer wraps a backing buffer.

Returns:
The root backing buffer or this if there is no backing buffer;
 
     Buffer buffer();
    
    

Returns:
a non volatile version of this Buffer value
 
     Buffer asNonVolatileBuffer();

    

Returns:
a readonly version of this Buffer.
 
     Buffer asReadOnlyBuffer();

    

Returns:
an immutable version of this Buffer.
 
     Buffer asImmutableBuffer();

    

Returns:
an immutable version of this Buffer.
 
     Buffer asMutableBuffer();
    
    
The capacity of the buffer. This is the maximum putIndex that may be set.

Returns:
an int value
 
     int capacity();
    
    
the space remaining in the buffer.

Returns:
capacity - putIndex
    int space();
    
    
Clear the buffer. getIndex=0, putIndex=0.
    void clear();

    
Compact the buffer by discarding bytes before the postion (or mark if set). Bytes from the getIndex (or mark) to the putIndex are moved to the beginning of the buffer and the values adjusted accordingly.
    void compact();
    
    
Get the byte at the current getIndex and increment it.

Returns:
The byte value from the current getIndex.
    byte get();
    
    
Get bytes from the current postion and put them into the passed byte array. The getIndex is incremented by the number of bytes copied into the array.

Parameters:
b The byte array to fill.
offset Offset in the array.
length The max number of bytes to read.
Returns:
The number of bytes actually read.
    int get(byte[] bint offsetint length);

    

Parameters:
length an int value
Returns:
a Buffer value
    Buffer get(int length);

    
The index within the buffer that will next be read or written.

Returns:
an int value >=0 <= putIndex()
    int getIndex();
    
    

Returns:
true of putIndex > getIndex
    boolean hasContent();
    
    

Returns:
a boolean value true if case sensitive comparison on this buffer
    boolean equalsIgnoreCase(Buffer buffer);


    

Returns:
a boolean value true if the buffer is immutable and that neither the buffer contents nor the indexes may be changed.
    boolean isImmutable();
    
    

Returns:
a boolean value true if the buffer is readonly. The buffer indexes may be modified, but the buffer contents may not. For example a View onto an immutable Buffer will be read only.
    boolean isReadOnly();
    
    

Returns:
a boolean value true if the buffer contents may change via alternate paths than this buffer. If the contents of this buffer are to be used outside of the current context, then a copy must be made.
    boolean isVolatile();

    
The number of bytes from the getIndex to the putIndex

Returns:
an int == putIndex()-getIndex()
    int length();
    
    
Set the mark to the current getIndex.
    void mark();
    
    
Set the mark relative to the current getIndex

Parameters:
offset an int value to add to the current getIndex to obtain the mark value.
    void mark(int offset);

    
The current index of the mark.

Returns:
an int index in the buffer or -1 if the mark is not set.
    int markIndex();

    
Get the byte at the current getIndex without incrementing the getIndex.

Returns:
The byte value from the current getIndex.
    byte peek();
  
    
Get the byte at a specific index in the buffer.

Parameters:
index an int value
Returns:
a byte value
    byte peek(int index);

    

Parameters:
index an int value
length an int value
Returns:
The Buffer value from the requested getIndex.
    Buffer peek(int indexint length);

    

Parameters:
index an int value
b The byte array to peek into
offset The offset into the array to start peeking
length an int value
Returns:
The number of bytes actually peeked
    int peek(int indexbyte[] bint offsetint length);
    
    
Put the contents of the buffer at the specific index.

Parameters:
index an int value
src a Buffer. If the source buffer is not modified
Returns:
The number of bytes actually poked
    int poke(int indexBuffer src);
    
    
Put a specific byte to a specific getIndex.

Parameters:
index an int value
b a byte value
    void poke(int indexbyte b);
    
    
Put a specific byte to a specific getIndex.

Parameters:
index an int value
b a byte array value
Returns:
The number of bytes actually poked
    int poke(int indexbyte b[], int offsetint length);
    
    
Write the bytes from the source buffer to the current getIndex.

Parameters:
src The source Buffer it is not modified.
Returns:
The number of bytes actually poked
    int put(Buffer src);

    
Put a byte to the current getIndex and increment the getIndex.

Parameters:
b a byte value
    void put(byte b);
    
    
Put a byte to the current getIndex and increment the getIndex.

Parameters:
b a byte value
Returns:
The number of bytes actually poked
    int put(byte[] b,int offsetint length);

    
Put a byte to the current getIndex and increment the getIndex.

Parameters:
b a byte value
Returns:
The number of bytes actually poked
    int put(byte[] b);

    
The index of the first element that should not be read.

Returns:
an int value >= getIndex()
    int putIndex();
    
    
Reset the current getIndex to the mark
    void reset();
    
    
Set the buffers start getIndex.

Parameters:
newStart an int value
    void setGetIndex(int newStart);
    
    
Set a specific value for the mark.

Parameters:
newMark an int value
    void setMarkIndex(int newMark);
    
    

Parameters:
newLimit an int value
    void setPutIndex(int newLimit);
    
    
Skip _content. The getIndex is updated by min(remaining(), n)

Parameters:
n The number of bytes to skip
Returns:
the number of bytes skipped.
    int skip(int n);

    

Returns:
a volitile Buffer from the postion to the putIndex.
    Buffer slice();
    
    

Returns:
a volitile Buffer value from the mark to the putIndex
    Buffer sliceFromMark();
    
    

Parameters:
length an int value
Returns:
a valitile Buffer value from the mark of the length requested.
    Buffer sliceFromMark(int length);
    
    

Returns:
a String value describing the state and contents of the buffer.
    /* ------------------------------------------------------------ */
    
Write the buffer's contents to the output stream

Parameters:
out
    void writeTo(OutputStream outthrows IOException;
    /* ------------------------------------------------------------ */
    
Read the buffer's contents from the input stream

Parameters:
in input stream
max maximum number of bytes that may be read
Returns:
actual number of bytes read or -1 for EOF
    int readFrom(InputStream inint maxthrows IOException;
    
    /* ------------------------------------------------------------ */
    String toString(String charset);
    
    /* ------------------------------------------------------------ */
    String toString(Charset charset);
    /*
     * Buffers implementing this interface should be compared with case insensitive equals
     *
     */
    public interface CaseInsensitve
    {}
    
New to GrepCode? Check out our FAQ X