Package com.google.gerrit.server.ioutil
Class LimitedByteArrayOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.google.gerrit.server.ioutil.LimitedByteArrayOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class LimitedByteArrayOutputStream extends OutputStream
A stream that throws an exception if it consumes data beyond a configured byte count.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LimitedByteArrayOutputStream.LimitExceededException
-
Constructor Summary
Constructors Constructor Description LimitedByteArrayOutputStream(int max, int initial)
Constructs a LimitedByteArrayOutputStream, which stores output in memory up to a certain specified size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
toByteArray()
Returns a newly allocated byte array with contents of the buffer.void
write(byte[] b, int off, int len)
void
write(int b)
-
Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream, write
-
-
-
-
Constructor Detail
-
LimitedByteArrayOutputStream
public LimitedByteArrayOutputStream(int max, int initial)
Constructs a LimitedByteArrayOutputStream, which stores output in memory up to a certain specified size. When the output exceeds the specified size a LimitExceededException is thrown.- Parameters:
max
- the maximum size in bytes which may be stored.initial
- the initial size. It must be smaller than the max size.
-
-
Method Detail
-
write
public void write(int b) throws IOException
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
toByteArray
public byte[] toByteArray()
Returns a newly allocated byte array with contents of the buffer.
-
-