At 10:14 PM 11/2/2004, you wrote:
It appears that UUEncoder is a subclass of
http://java.sun.com/products/commerce/docs/api/javax.commerce.util.CharacterEncoder.html

This program seems to do something interesting...

public class UUEncodeTest {
  public static void main(String argv[]) throws IOException {
    UUEncoder encoder = new UUEncoder("foo",777); // ?
    UUDecoder decoder = new UUDecoder();
    byte bytes[] = new byte[] { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 };
    String encoded = encoder.encodeBuffer(bytes);
    byte decoded[] = decoder.decodeBuffer(encoded);
    if(!Arrays.equals(bytes,decoded))
      throw new RuntimeException(Arrays.toString(bytes) + " != " + Arrays.toString(decoded));
    System.out.println(encoded);
  }
}

Here's the output:

Thanks Andy!  I had just managed to find an example online of how to use the UUEncode
but yours is better.


The effect of the constructor arguments is obvious (and they're unnecessary), but their meaning is totally unclear to me.

I didn't understand this sentence so......
The UUEncoder arguments specify the name and the Unix permissions mode
of the outputfile file as incorporated on the 'begin' line of the uuencoded data.
So, for your example, you'll see something like:

begin 777 foo.gif
UUUUUUUencoded data hereUUUUUUUUUU
........
end

And, just to give back to this thread, here's my kludgy routine to
use UUEncode:

  /**
   * Uuencode the contents of the given file and return them as a string.
   *
   * @param inFile the input file whose contents are to be uuencoded.
   * @param targetFilePath the file pathname for the decoded target file.
   * @param mode the Unix permissions mode for the decoded target file.
   *
   * @return a <tt>String</tt> containing the uuencoded file contents.
   */
  public static String uuencodeFile (File inFile,
                                     String targetFilePath, int mode)
    throws IOException, MessagingException
  {
    FileInputStream finstream = new FileInputStream(inFile);
    int bufSize = (2 * finstream.available()) + 1024;
    ByteArrayOutputStream baos = new ByteArrayOutputStream(bufSize);
    sun.misc.CharacterEncoder encoder = new UUEncoder(targetFilePath, mode);
    encoder.encode(finstream, baos);
    return baos.toString();
  }

Thanks again,
        -tom



Thomas Hicks wrote:
At 06:10 PM 11/2/2004, you wrote:

Looks like there are bits built into Java itself:  sun.misc.UUEncoder

Thanks Eric. I saw this but couldn't find any docs on how to use it.

Reply via email to