code: static int getLength(int lenByte, InputStream in) throws IOException {
          int value, tmp;
  
          tmp = lenByte;
          if ((tmp & 0x080) == 0x00) { // short form, 1 byte datum
              value = tmp;
          } else {                     // long form or indefinite
              tmp &= 0x07f;
  
              /*
               * NOTE:  tmp == 0 indicates indefinite length encoded data.
               * tmp > 4 indicates more than 4Gb of data.
               */
              if (tmp == 0)
                  return -1;
              if (tmp < 0 || tmp > 4)
                  throw new IOException("DerInputStream.getLength(): lengthTag="
                      + tmp + ", "
                      + ((tmp < 0) ? "incorrect DER encoding." : "too big."));
  
              for (value = 0; tmp > 0; tmp --) {
                  value <<= 8;
                  value += 0x0ff & in.read();
              }
              if (value < 0) {
                  throw new IOException("DerInputStream.getLength(): "
                          + "Invalid length bytes");
              }
          }
          return value;
      }
docs: /*
  Get a length from the input stream, allowing for at most 32 bits of
  encoding to be used.  (Not the same as getting a tagged integer!)
  
  @return the length or -1 if indefinite length found.
  @exception IOException on parsing error or unsupported lengths.