Package i2p.susi.util
Class MemoryBuffer
java.lang.Object
i2p.susi.util.MemoryBuffer
- All Implemented Interfaces:
Buffer
public class MemoryBuffer extends Object implements Buffer
Buffer backed by a byte array.
Use for small amounts of data only.
- Since:
- 0.9.34
-
Constructor Summary
Constructors Constructor Description MemoryBuffer()
MemoryBuffer(int size)
-
Method Summary
Modifier and Type Method Description byte[]
getContent()
InputStream
getInputStream()
int
getLength()
Current size.int
getOffset()
OutputStream
getOutputStream()
void
readComplete(boolean success)
Top-level reader MUST call this to close the input stream.String
toString()
void
writeComplete(boolean success)
Deletes the data if success is false
-
Constructor Details
-
MemoryBuffer
public MemoryBuffer() -
MemoryBuffer
public MemoryBuffer(int size)
-
-
Method Details
-
getInputStream
- Specified by:
getInputStream
in interfaceBuffer
- Returns:
- new ByteArrayInputStream
- Throws:
IOException
-
getOutputStream
- Specified by:
getOutputStream
in interfaceBuffer
- Returns:
- new or existing ByteArrayOutputStream
-
readComplete
public void readComplete(boolean success)Description copied from interface:Buffer
Top-level reader MUST call this to close the input stream.- Specified by:
readComplete
in interfaceBuffer
-
writeComplete
public void writeComplete(boolean success)Deletes the data if success is false- Specified by:
writeComplete
in interfaceBuffer
- Parameters:
success
- if false, deletes any resources
-
getLength
public int getLength()Current size. -
getOffset
public int getOffset() -
getContent
public byte[] getContent()- Returns:
- content if writeComplete(true) was called, otherwise null
-
toString
-