public static int decode(byte[] data,OutputStream out) throws IOException {
  int off=0;
  int length=data.length;
  int endOffset=off + length;
  int bytesWritten=0;
  while (off < endOffset) {
    byte ch=data[off++];
    if (ch == '_') {
      out.write(' ');
    }
 else     if (ch == '=') {
      if (off + 1 >= endOffset) {
        throw new IOException("Invalid quoted printable encoding; truncated escape sequence");
      }
      byte b1=data[off++];
      byte b2=data[off++];
      if (b1 == '\r') {
        if (b2 != '\n') {
          throw new IOException("Invalid quoted printable encoding; CR must be followed by LF");
        }
      }
 else {
        int c1=hexToBinary(b1);
        int c2=hexToBinary(b2);
        out.write((c1 << UPPER_NIBBLE_SHIFT) | c2);
        bytesWritten++;
      }
    }
 else {
      out.write(ch);
      bytesWritten++;
    }
  }
  return bytesWritten;
}

public static int decode ( byte [ ] data , OutputStream out ) throws IOException { int off = 0 ; int length = data . length ; int endOffset = off + length ; int bytesWritten = 0 ; while ( off < endOffset ) { byte ch = data [ off ++ ] ; if ( ch == '_' ) { out . write ( ' ' ) ; } else if ( ch == '=' ) { if ( off + 1 >= endOffset ) { throw new IOException ( "Invalid quoted printable encoding; truncated escape sequence" ) ; } byte b1 = data [ off ++ ] ; byte b2 = data [ off ++ ] ; if ( b1 == '\r' ) { if ( b2 != '\n' ) { throw new IOException ( "Invalid quoted printable encoding; CR must be followed by LF" ) ; } } else { int c1 = hexToBinary ( b1 ) ; int c2 = hexToBinary ( b2 ) ; out . write ( ( c1 << UPPER_NIBBLE_SHIFT ) | c2 ) ; bytesWritten ++ ; } } else { out . write ( ch ) ; bytesWritten ++ ; } } return bytesWritten ; }
decode the encoded byte data writing it to the given output stream .
