2362N/A * Copyright (c) 1995, 2004, 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 implements a Berkeley uu character encoder. This encoder 0N/A * was made famous by uuencode program. 0N/A * The basic character coding is algorithmic, taking 6 bits of binary 0N/A * data and adding it to an ASCII ' ' (space) character. This converts 0N/A * these six bits into a printable representation. Note that it depends 0N/A * on the ASCII character encoding standard for english. Groups of three 0N/A * bytes are converted into 4 characters by treating the three bytes 0N/A * a four 6 bit groups, group 1 is byte 1's most significant six bits, 0N/A * group 2 is byte 1's least significant two bits plus byte 2's four 0N/A * most significant bits. etc. 0N/A * In this encoding, the buffer prefix is: 0N/A * begin [mode] [filename] 0N/A * This is followed by one or more lines of the form: 0N/A * (len)(data)(data)(data) ... 0N/A * where (len) is the number of bytes on this line. Note that groupings 0N/A * are always four characters, even if length is not a multiple of three 0N/A * bytes. When less than three characters are encoded, the values of the 0N/A * last remaining bytes is undefined and should be ignored. 0N/A * The last line of data in a uuencoded file is represented by a single 0N/A * space character. This is translated by the decoding engine to a line 0N/A * length of zero. This is immediately followed by a line which contains 0N/A * the word 'end[newline]' 0N/A * @author Chuck McManis 0N/A * @see CharacterEncoder 0N/A * This name is stored in the begin line. 0N/A * Represents UNIX(tm) mode bits. Generally three octal digits representing 0N/A * read, write, and execute permission of the owner, group owner, and 0N/A * others. They should be interpreted as the bit groups: 0N/A * (owner) (group) (others) 0N/A * rwx rwx rwx (r = read, w = write, x = execute) 0N/A * By default these are set to 644 (UNIX rw-r--r-- permissions). 0N/A * Default - buffer begin line will be: 0N/A * begin 644 encoder.buf 0N/A * Specifies a name for the encoded buffer, begin line will be: 0N/A * Specifies a name and mode for the encoded buffer, begin line will be: 0N/A * begin [MODE] [FNAME] 0N/A /** number of bytes per atom in uuencoding is 3 */ 0N/A /** number of bytes per line in uuencoding is 45 */ 0N/A * encodeAtom - take three bytes and encodes them into 4 characters 0N/A * If len is less than 3 then remaining bytes are filled with '1'. 0N/A * This insures that the last line won't end in spaces and potentiallly 0N/A byte a, b =
1, c =
1;
0N/A c2 = ((a <<
4) &
0x30) | ((b >>>
4) &
0xf);
0N/A c3 = ((b <<
2) &
0x3c) | ((c >>>
6) &
0x3);
0N/A * Encode the line prefix which consists of the single character. The 0N/A * lenght is added to the value of ' ' (32 decimal) and printed. 0N/A * The line suffix for uuencoded files is simply a new line. 0N/A * encodeBufferPrefix writes the begin line to the output stream. 0N/A * encodeBufferSuffix writes the single line containing space (' ') and 0N/A * the line containing the word 'end' to the output stream.