BufferedinputStream default buffer size is 8k for my jvm. Is that a harcoded value, or can it be changed by altering some system parameter?
I'd like it to use 128k without modifying the java code. Is that possible?
Thanks,
BufferedinputStream default buffer size is 8k for my jvm. Is that a harcoded value, or can it be changed by altering some system parameter?
I'd like it to use 128k without modifying the java code. Is that possible?
Thanks,
It's not your JVM, but Java defines the default value of 8K for the BufferedInputStream.
You can't change it from outside, without modifying your java program.
To modify from Java, you need to pass the SIZE in Stream constructor.
new BufferedInputStream(file, size * 1024); where size can be 128 for 128KB.
There is no way to change the default buffer size by a system property. You must use the constructor which accepts a size argument. The only place the buffer is created is in this constructor:
public BufferedInputStream(InputStream in, int size) {
super(in);
if (size <= 0) {
throw new IllegalArgumentException("Buffer size <= 0");
}
buf = new byte[size];
}
This applies for my JVM version (1.8.0_31) but it could possibly be different on other implementations.
You may use the BufferedInputStream(InputStream in, int size) constructor. But don't change it unless it is very necessary.