Browse Source

remove use of sun.misc.uuencoder

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@466879 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
3510e9c820
3 changed files with 143 additions and 9 deletions
  1. +0
    -8
      build.xml
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/email/UUMailer.java
  3. +142
    -0
      src/main/org/apache/tools/ant/util/UUEncoder.java

+ 0
- 8
build.xml View File

@@ -191,10 +191,6 @@
</or> </or>
</selector> </selector>


<selector id="needs.sun.uue">
<filename name="${ant.package}/taskdefs/email/UUMailer*"/>
</selector>

<!-- depends on external libraries --> <!-- depends on external libraries -->
<selector id="needs.trax"> <selector id="needs.trax">
<or> <or>
@@ -470,9 +466,6 @@
<available property="bcel.present" <available property="bcel.present"
classname="org.apache.bcel.Constants" classname="org.apache.bcel.Constants"
classpathref="classpath"/> classpathref="classpath"/>
<available property="sunuue.present"
classname="sun.misc.UUEncoder"
classpathref="classpath"/>


<condition property="javamail.complete"> <condition property="javamail.complete">
<and> <and>
@@ -646,7 +639,6 @@
<selector refid="needs.jdk1.4+" unless="jdk1.4+"/> <selector refid="needs.jdk1.4+" unless="jdk1.4+"/>
<selector refid="needs.jdk1.5+" unless="jdk1.5+"/> <selector refid="needs.jdk1.5+" unless="jdk1.5+"/>
<selector refid="not.in.kaffe" if="kaffe"/> <selector refid="not.in.kaffe" if="kaffe"/>
<selector refid="needs.sun.uue" unless="sunuue.present"/>


<selector refid="needs.trax" unless="trax.present"/> <selector refid="needs.trax" unless="trax.present"/>
<selector refid="needs.apache-resolver" unless="apache.resolver.present"/> <selector refid="needs.apache-resolver" unless="apache.resolver.present"/>


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/email/UUMailer.java View File

@@ -23,7 +23,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import sun.misc.UUEncoder;
import org.apache.tools.ant.util.UUEncoder;


/** /**
* An emailer that uuencodes attachments. * An emailer that uuencodes attachments.


+ 142
- 0
src/main/org/apache/tools/ant/util/UUEncoder.java View File

@@ -0,0 +1,142 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.tools.ant.util;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
/**
* UUEncoding of an input stream placed into an outputstream.
* This class is meant to be a drop in replacement for
* sun.misc.UUEncoder, which was previously used by Ant.
* The uuencode algorithm code has been copied from the
* geronimo project.
**/
public class UUEncoder {
protected static final int DEFAULT_MODE = 644;
private static final int MAX_CHARS_PER_LINE = 45;
private OutputStream out;
private String name;
/**
* Constructor specifing a name for the encoded buffer, begin
* line will be:
* <pre>
* begin 644 [NAME]
* </pre>
* @param name the name of the encoded buffer.
*/
public UUEncoder(String name) {
this.name = name;
}
/**
* UUEncode bytes from the input stream, and write them as text characters
* to the output stream. This method will run until it exhausts the
* input stream.
* @param is the input stream.
* @param out the output stream.
*/
public void encode(InputStream is, OutputStream out)
throws IOException {
this.out = out;
encodeBegin();
byte[] buffer = new byte[MAX_CHARS_PER_LINE * 100];
int count;
while ((count = is.read(buffer, 0, buffer.length)) != -1) {
int pos = 0;
while (count > 0) {
int num = count > MAX_CHARS_PER_LINE
? MAX_CHARS_PER_LINE
: count;
encodeLine(buffer, pos, num, out);
pos += num;
count -= num;
}
}
out.flush();
encodeEnd();
}
/**
* Encode a string to the output.
*/
private void encodeString(String n) throws IOException {
PrintStream writer = new PrintStream(out);
writer.print(n);
writer.flush();
}
private void encodeBegin() throws IOException {
encodeString("begin " + DEFAULT_MODE + " " + name + "\n");
}
private void encodeEnd() throws IOException {
encodeString(" \nend\n");
}
/**
* Encode a single line of data (less than or equal to 45 characters).
*
* @param data The array of byte data.
* @param off The starting offset within the data.
* @param length Length of the data to encode.
* @param out The output stream the encoded data is written to.
*
* @exception IOException
*/
private void encodeLine(
byte[] data, int offset, int length, OutputStream out)
throws IOException {
// write out the number of characters encoded in this line.
out.write((byte)((length & 0x3F) + ' '));
byte a;
byte b;
byte c;
for (int i = 0; i < length;) {
// set the padding defaults
b = 1;
c = 1;
// get the next 3 bytes (if we have them)
a = data[offset + i++];
if (i < length) {
b = data[offset + i++];
if (i < length) {
c = data[offset + i++];
}
}
byte d1 = (byte)(((a >>> 2) & 0x3F) + ' ');
byte d2 = (byte)(((( a << 4) & 0x30) | ((b >>> 4) & 0x0F)) + ' ');
byte d3 = (byte)((((b << 2) & 0x3C) | ((c >>> 6) & 0x3)) + ' ');
byte d4 = (byte)((c & 0x3F) + ' ');
out.write(d1);
out.write(d2);
out.write(d3);
out.write(d4);
}
// terminate with a linefeed alone
out.write('\n');
}
}

Loading…
Cancel
Save