protected int fill() throws IOException {
		if (packetLen >= 0) {
			// test if it was the last package
			if (packetLen == 0 && partial == false) {
				// stream ends here
				len = -1;
				return -1;
			}

			fillInputBuf();

			if (packetLen == 0 && partial) {
				decodePacketLen();
			}

			len = (int) Math.min((long) inputLen, packetLen);
			pos = inputPos;
			inputPos += len;
			inputLen -= len;
			packetLen -= len;

			return len;
		} else {
			if (len == -1 || fillInputBuf() < 0) {
				// stream ends here
				len = -1;
				return -1;
			}

			len = inputLen;
			pos = inputPos;
			inputPos += len;
			inputLen -= len;

			return len;
		}
	}