private int getKnownLength(InputStream inputStream) throws IOException { if (inputStream instanceof KnownLength || inputStream instanceof ByteArrayInputStream) { return inputStream.available(); } return -1; }