private boolean decode5(ByteArrayOutputStream baos) throws PDFParseException {
  int[] five=new int[5];
  int i;
  for (i=0; i < 5; i++) {
    five[i]=nextChar();
    if (five[i] == '~') {
      if (nextChar() == '>') {
        break;
      }
 else {
        throw new PDFParseException("Bad character in ASCII85Decode: not ~>");
      }
    }
 else     if (five[i] >= '!' && five[i] <= 'u') {
      five[i]-='!';
    }
 else     if (five[i] == 'z') {
      if (i == 0) {
        five[i]=0;
        i=4;
      }
 else {
        throw new PDFParseException("Inappropriate 'z' in ASCII85Decode");
      }
    }
 else {
      throw new PDFParseException("Bad character in ASCII85Decode: " + five[i] + " ("+ (char)five[i]+ ")");
    }
  }
  if (i > 0) {
    i-=1;
  }
  int value=five[0] * 85 * 85* 85* 85 + five[1] * 85 * 85* 85 + five[2] * 85 * 85 + five[3] * 85 + five[4];
  for (int j=0; j < i; j++) {
    int shift=8 * (3 - j);
    baos.write((byte)((value >> shift) & 0xff));
  }
  return (i == 4);
}

private boolean decode5 ( ByteArrayOutputStream baos ) throws PDFParseException { int [ ] five = new int [ 5 ] ; int i ; for ( i = 0 ; i < 5 ; i ++ ) { five [ i ] = nextChar ( ) ; if ( five [ i ] == '~' ) { if ( nextChar ( ) == '>' ) { break ; } else { throw new PDFParseException ( "Bad character in ASCII85Decode: not ~>" ) ; } } else if ( five [ i ] >= '!' && five [ i ] <= 'u' ) { five [ i ] -= '!' ; } else if ( five [ i ] == 'z' ) { if ( i == 0 ) { five [ i ] = 0 ; i = 4 ; } else { throw new PDFParseException ( "Inappropriate 'z' in ASCII85Decode" ) ; } } else { throw new PDFParseException ( "Bad character in ASCII85Decode: " + five [ i ] + " (" + ( char ) five [ i ] + ")" ) ; } } if ( i > 0 ) { i -= 1 ; } int value = five [ 0 ] * 85 * 85 * 85 * 85 + five [ 1 ] * 85 * 85 * 85 + five [ 2 ] * 85 * 85 + five [ 3 ] * 85 + five [ 4 ] ; for ( int j = 0 ; j < i ; j ++ ) { int shift = 8 * ( 3 - j ) ; baos . write ( ( byte ) ( ( value > > shift ) & 0xff ) ) ; } return ( i == 4 ) ; }
decode the next five ascii85 characters into up to four decoded bytes . return false when finished , or true otherwise .
