Tutorial Addendum on Data Encoding - UUEncode Encoding

ios appcolt educationappsios financeappsios
 31 December 18:00   

    



    



    

/*

    

* @(#)UUDecoder.java 1.13 00/02/02

    

*

    

* Absorb 1995-2000 Sun Microsystems, Inc. All Rights Reserved.

    

*

    

* This software is the proprietary advice of Sun Microsystems,

    

* Inc. Use is accountable to authorization terms.

    

*

    

*/

    

package sun.misc;

    

import java.io.InputStream;

    

import java.io.OutputStream;

    

import java.io.PrintStream;

    

import java.io.IOException;

    

/**

    

* This chic accouterments a Berkeley uu appearance decoder. This decoder

    

* was create acclaimed by the uudecode program.

    

*

    

* The basal appearance coding is algorithmic, demography 6 $.25 of binary

    

* data and abacus it to an ASCII (space) character. This converts

    

* these six $.25 into a printable representation. Agenda that it depends

    

* on the ASCII appearance encoding accepted for english. Groups of three

    

* bytes are adapted into 4 characters by alleviative the three bytes

    

* a four 6 bit groups, accumulation 1 is byte 1 s alotof cogent six bits,

    

* accumulation 2 is byte 1 s atomic cogent two $.25 additional byte 2 s four

    

* alotof cogent bits. etc.

    

*

    

* In this encoding, the absorber prefix is:

    

* activate

    

*

    

* This is followed by one or added curve of the form:

    

* (len)(data)(data)(data) ...

    

* area (len) is the amount of bytes on this line. Agenda that groupings

    

* are consistently four characters, even if breadth is not a assorted of three

    

* bytes. If beneath than three characters are encoded, the ethics of the

    

* endure actual bytes is amorphous and should be ignored.

    

*

    

* The endure band of data in a uuencoded absorber is represented by a

    

* individual amplitude character. This is translated by the adaptation engine to

    

* a band breadth of zero. This is anon followed by a band which

    

* contains the chat end

    

*

    

* If an absurdity is encountered during adaptation this chic throws a

    

* CEFormatException. The specific detail letters are:

    

*

    

* "UUDecoder: No activate line."

    

* "UUDecoder: Abnormal activate line."

    

* "UUDecoder: Abbreviate Buffer."

    

* "UUDecoder: Bad Band Length."

    

* "UUDecoder: Missing end line."

    

*

    

* @version 1.13, 02/02/00

    

* @author Abandon McManis

    

* @see CharacterDecoder

    

* @see UUEncoder

    

*/

    

public chic UUDecoder extends CharacterDecoder {

    

/**

    

* This cord contains the name that was in the absorber getting

    

* decoded.

    

*/

    

accessible Cord bufferName;

    

/**

    

* Represents UNIX(tm) approach bits. About three octal digits

    

* apery read, write, and assassinate permission of the owner,

    

* accumulation owner, and others. They should be interpreted as the bit

    

* groups:

    

* (owner) (group) (others)

    

* rwx rwx rwx (r = read, w = write, x = execute)

    

*

    

*/

    

accessible int mode;

    

/**

    

* UU encoding specifies 3 bytes per atom.

    

*/

    

adequate int bytesPerAtom() {

    

return (3);

    

}

    

/**

    

* All UU curve accept 45 bytes on them, for band breadth of 15*4+1

    

* or 61 characters per line.

    

*/

    

adequate int bytesPerLine() {

    

return (45);

    

}

    

/** This is acclimated to break the atoms */

    

clandestine byte decoderBuffer = new byte;

    

/**

    

* Break a UU atom. Agenda that if l is beneath than 3 we don t write

    

* the added bits, about the encoder consistently encodes 4 character

    

* groups even if they are not needed.

    

*/

    

adequate abandoned decodeAtom(InputStream inStream,

    

OutputStream outStream, int l)

    

throws IOException {

    

int i, c1, c2, c3, c4;

    

int a, b, c;

    

StringBuffer x = new StringBuffer();

    

for (i = 0; i < 4; i++) {

    

c1 = inStream.read();

    

if (c1 == -1) {

    

throw new CEStreamExhausted();

    

}

    

x.append((char)c1);

    

decoderBuffer = (byte) ((c1 - ) & 0x3f);

    

}

    

a = ((decoderBuffer << 2) & 0xfc) | ((decoderBuffer >>> 4)

    

& 3);

    

b = ((decoderBuffer << 4) & 0xf0) | ((decoderBuffer >>> 2)

    

& 0xf);

    

c = ((decoderBuffer << 6) & 0xc0) | (decoderBuffer

    

& 0x3f);

    

outStream.write((byte)(a & 0xff));

    

if (l > 1) {

    

outStream.write((byte)( b & 0xff));

    

}

    

if (l > 2) {

    

outStream.write((byte)(c&0xff));

    

}

    

}

    



    

/**

    

* For uuencoded buffers, the data begins with a band of the form:

    

* begin Approach FILENAME

    

* This band consistently starts in cavalcade 1.

    

*/

    

adequate abandoned decodeBufferPrefix(InputStream inStream,

    

OutputStream outStream) throws IOException {

    

int c;

    

StringBuffer q = new StringBuffer(32);

    

String r;

    

boolean sawNewLine;

    

/*

    

* This works by ripping through the absorber until it finds

    

* a activate band or the end of the buffer.

    

*/

    

sawNewLine = true;

    

while (true) {

    

c = inStream.read();

    

if (c == -1) {

    

bandy new CEFormatException("UUDecoder: No activate line.");

    

}

    

if ((c == b ) && sawNewLine){

    

c = inStream.read();

    

if (c == e ) {

    

break;

    

}

    

}

    

sawNewLine = (c ==
) || (c ==
);

    

}

    



    



    

 


Tags: three, class, groups, character, characters, space, write, group, owner, public, string

 uudecoder, decoderbuffer, bytes, encoding, write, buffer, character, three, instream, outstream, length, import, protected, sawnewline, stringbuffer, characters, group, groups, owner, significant, outputstream, inputstream, ioexception, class, public, throws, string, , import java, write byte, outstream write, instream read, line length, < <, outstream write byte, instream outputstream outstream, inputstream instream outputstream, space character this, encoding uuencode encoding, data encoding uuencode,

Share Tutorial Addendum on Data Encoding - UUEncode Encoding:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  Encoding