2362N/A * Copyright (c) 1995, 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class defines the encoding half of character encoders. 0N/A * A character encoder is an algorithim for transforming 8 bit binary 0N/A * data into text (generally 7 bit ASCII or 8 bit ISO-Latin-1 text) 0N/A * for transmition over text channels such as e-mail and network news. 0N/A * The character encoders have been structured around a central theme 0N/A * that, in general, the encoded text has the form: 0N/A * [Line Prefix][encoded data atoms][Line Suffix] 0N/A * In the CharacterEncoder and CharacterDecoder classes, one complete 0N/A * chunk of data is referred to as a <i>buffer</i>. Encoded buffers 0N/A * are all text, and decoded buffers (sometimes just referred to as 0N/A * buffers) are binary octets. 0N/A * To create a custom encoder, you must, at a minimum, overide three 0N/A * abstract methods in this class. 0N/A * <DD>bytesPerAtom which tells the encoder how many bytes to 0N/A * send to encodeAtom 0N/A * <DD>encodeAtom which encodes the bytes sent to it as text. 0N/A * <DD>bytesPerLine which tells the encoder the maximum number of 0N/A * Several useful encoders have already been written and are 0N/A * referenced in the See Also list below. 0N/A * @author Chuck McManis 0N/A * @see CharacterDecoder; 0N/A * @see BASE64Encoder 0N/A /** Stream that understands "printing" */ 0N/A /** Return the number of bytes per atom of encoding */ 0N/A /** Return the number of bytes that can be encoded per line */ 0N/A * Encode the prefix for the entire buffer. By default is simply 0N/A * opens the PrintStream for use by the other functions. 0N/A * Encode the suffix for the entire buffer. 0N/A * Encode the prefix that starts every output line. 0N/A * Encode the suffix that ends every output line. By default 0N/A * this method just prints a <newline> into the output stream. 0N/A /** Encode one "atom" of information into characters. */ 0N/A * This method works around the bizarre semantics of BufferedInputStream's 0N/A * Encode bytes from the input stream, and write them as text characters 0N/A * to the output stream. This method will run until it exhausts the 0N/A * input stream, but does not print the line suffix for a final 0N/A * line that is shorter than bytesPerLine(). 0N/A * Encode the buffer in <i>aBuffer</i> and write the encoded 0N/A * result to the OutputStream <i>aStream</i>. 0N/A * A 'streamless' version of encode that simply takes a buffer of 0N/A * bytes and returns a string containing the encoded buffer. 0N/A // explicit ascii->unicode conversion 0N/A // This should never happen. 0N/A throw new Error(
"CharacterEncoder.encode internal error");
0N/A * Return a byte array from the remaining bytes in this ByteBuffer. 0N/A * The ByteBuffer's position will be advanced to ByteBuffer's limit. 0N/A * To avoid an extra copy, the implementation will attempt to return the 0N/A * byte array backing the ByteBuffer. If this is not possible, a 0N/A * new byte array will be created. 0N/A * This should never return a BufferOverflowException, as we're 0N/A * careful to allocate just the right amount. 0N/A * If it has a usable backing byte buffer, use it. Use only 0N/A * if the array exactly represents the current ByteBuffer. 0N/A * This class doesn't have a concept of encode(buf, len, off), 0N/A * so if we have a partial buffer, we must reallocate 0N/A * position() automatically updated 0N/A * Encode the <i>aBuffer</i> ByteBuffer and write the encoded 0N/A * result to the OutputStream <i>aStream</i>. 0N/A * The ByteBuffer's position will be advanced to ByteBuffer's limit. 0N/A * A 'streamless' version of encode that simply takes a ByteBuffer 0N/A * and returns a string containing the encoded buffer. 0N/A * The ByteBuffer's position will be advanced to ByteBuffer's limit. 0N/A * Encode bytes from the input stream, and write them as text characters 0N/A * to the output stream. This method will run until it exhausts the 0N/A * input stream. It differs from encode in that it will add the 0N/A * line at the end of a final line that is shorter than bytesPerLine(). 0N/A * Encode the buffer in <i>aBuffer</i> and write the encoded 0N/A * result to the OutputStream <i>aStream</i>. 0N/A * A 'streamless' version of encode that simply takes a buffer of 0N/A * bytes and returns a string containing the encoded buffer. 0N/A // This should never happen. 0N/A throw new Error(
"CharacterEncoder.encodeBuffer internal error");
0N/A * Encode the <i>aBuffer</i> ByteBuffer and write the encoded 0N/A * result to the OutputStream <i>aStream</i>. 0N/A * The ByteBuffer's position will be advanced to ByteBuffer's limit. 0N/A * A 'streamless' version of encode that simply takes a ByteBuffer 0N/A * and returns a string containing the encoded buffer. 0N/A * The ByteBuffer's position will be advanced to ByteBuffer's limit.