LimitedTemporaryStorage: Fix perf bug. (#3432)

FilterOutputStream has an inefficient implementation of write(byte[], int, int).
So let's extend OutputStream directly and use efficient implementations of all
methods.
This commit is contained in:
Gian Merlino 2016-09-06 15:39:36 -07:00 committed by GitHub
parent 6827c09311
commit 1d07964987
1 changed files with 23 additions and 5 deletions

View File

@ -110,6 +110,11 @@ public class LimitedTemporaryStorage implements Closeable
} }
} }
public long maxSize()
{
return maxBytesUsed;
}
@Override @Override
public void close() public void close()
{ {
@ -128,35 +133,48 @@ public class LimitedTemporaryStorage implements Closeable
} }
} }
public class LimitedOutputStream extends FilterOutputStream public class LimitedOutputStream extends OutputStream
{ {
private final File file; private final File file;
private final OutputStream out;
private LimitedOutputStream(File file, OutputStream out) private LimitedOutputStream(File file, OutputStream out)
{ {
super(out);
this.file = file; this.file = file;
this.out = out;
} }
@Override @Override
public void write(int b) throws IOException public void write(int b) throws IOException
{ {
grab(1); grab(1);
super.write(b); out.write(b);
} }
@Override @Override
public void write(byte[] b) throws IOException public void write(byte[] b) throws IOException
{ {
grab(b.length); grab(b.length);
super.write(b); out.write(b);
} }
@Override @Override
public void write(byte[] b, int off, int len) throws IOException public void write(byte[] b, int off, int len) throws IOException
{ {
grab(len); grab(len);
super.write(b, off, len); out.write(b, off, len);
}
@Override
public void flush() throws IOException
{
out.flush();
}
@Override
public void close() throws IOException
{
out.close();
} }
public File getFile() public File getFile()