Revision history [back]

click to hide/show revision 1
initial version

answered 2016-09-20 11:57:04 +0800

IngoB gravatar image IngoB flag of Germany

otherwise you can count the written bytes and stop it after 2gb

final long MAX_SIZE = 2147483648L;
long currentSize = 0;
byte[] buffer = new byte[1024 * 8];
for (int count; (count = inputStream.read(buffer)) != -1;) {
    outputStream.write(buffer, 0, count);
    currentSize += count;
    if (currentSize >= MAX_SIZE) {
        System.out.println("too big!");
        break;
    }
}

otherwise you can count the written bytes and stop it after 2gb

final long MAX_SIZE = 2147483648L;
long currentSize = 0;
byte[] buffer = new byte[1024 * 8];
for (int count; (count = inputStream.read(buffer)) != -1;) {
{  outputStream.write(buffer, 0, count);
     currentSize += count;
    if (currentSize >= MAX_SIZE) {
        System.out.println("too big!");
        break;
    }
    outputStream.write(buffer, 0, count);
}
Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More