Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; public class Main { public static int parseLength(InputStream input) throws IOException { int complexTag = 0; int nextByte = input.read(); boolean isComplexLength = (nextByte & 0x80) > 0; if (isComplexLength) { int bytesCount = nextByte & 0x7f; for (int i = 0; i < bytesCount; i++) { complexTag <<= 8; complexTag |= input.read(); } return complexTag; } else { return nextByte & 0x7f; } } }