public static byte[] readBlobAndClose(InputStream in, int length) throws IOException {
		try {
			if (length <= 0) {
				length = Integer.MAX_VALUE;
			}
			int block = Math.min(BUFFER_BLOCK_SIZE, length);
			ByteArrayOutputStream out = new ByteArrayOutputStream(length == Integer.MAX_VALUE ? block
					: length);
			byte[] buff = new byte[block];
			while (length > 0) {
				int len = Math.min(block, length);
				len = in.read(buff, 0, len);
				if (len < 0) {
					break;
				}
				out.write(buff, 0, len);
				length -= len;
			}
			return out.toByteArray();
		} finally {
			in.close();
		}
	}