I tried to copy an InputStream to a File, and abort the copy if the size of InputStream is greater than 1MB. In Java7, I wrote code as below:
public void cop
Much more convenient and faster solution to check size of input stream
FileChannel chanel = (FileChannel) Channels.newChannel(inputStream); MappedByteBuffer buffer = chanel.map(FileChannel.MapMode.READ_ONLY, 0, chanel.size()); System.out.println(buffer.capacity()); // bytes