325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * This class implements a Quoted Printable Encoder. It is implemented as 325N/A * a FilterOutputStream, so one can just wrap this class around 325N/A * any output stream and write bytes into this filter. The Encoding 325N/A * is done as the bytes are written out. 325N/A private int count =
0;
// number of bytes that have been output 325N/A * Create a QP encoder that encodes the specified input stream 325N/A * @param out the output stream 325N/A * @param bytesPerLine the number of bytes per line. The encoder 325N/A * inserts a CRLF sequence after this many number 325N/A // Subtract 1 to account for the '=' in the soft-return 325N/A // at the end of a line 325N/A * Create a QP encoder that encodes the specified input stream. 325N/A * Inserts the CRLF sequence after outputting 76 bytes. 325N/A * @param out the output stream 325N/A * Encodes <code>len</code> bytes from the specified 325N/A * <code>byte</code> array starting at offset <code>off</code> to 325N/A * @param off the start offset in the data. 325N/A * @param len the number of bytes to write. 325N/A * @exception IOException if an I/O error occurs. 325N/A * Encodes <code>b.length</code> bytes to this output stream. 325N/A * @param b the data to be written. 325N/A * @exception IOException if an I/O error occurs. 325N/A * Encodes the specified <code>byte</code> to this output stream. 325N/A * @param c the <code>byte</code>. 325N/A * @exception IOException if an I/O error occurs. 325N/A c = c &
0xff;
// Turn off the MSB. 325N/A if (c ==
'\r' || c ==
'\n')
325N/A // if CR/LF, we need to encode the <SPACE> char 325N/A else // no encoding required, just output the char 325N/A // This is a CRLF sequence, we already output the 325N/A // corresponding CRLF when we got the CR, so ignore this 325N/A }
else if (c <
040 || c >=
0177 || c ==
'=')
325N/A else // No encoding required 325N/A // whatever it was, it wasn't a CR 325N/A * Flushes this output stream and forces any buffered output bytes 325N/A * to be encoded out to the stream. 325N/A * @exception IOException if an I/O error occurs. 325N/A * Forces any buffered output bytes to be encoded out to the stream 325N/A * and closes this output stream 325N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
325N/A '8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' 325N/A /**** begin TEST program *** 325N/A public static void main(String argv[]) throws Exception { 325N/A FileInputStream infile = new FileInputStream(argv[0]); 325N/A QPEncoderStream encoder = new QPEncoderStream(System.out); 325N/A while ((c = infile.read()) != -1) 325N/A *** end TEST program ***/