1 | /*
|
---|
2 | * Copyright 2002,2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.email;
|
---|
18 |
|
---|
19 | import java.io.BufferedInputStream;
|
---|
20 | import java.io.File;
|
---|
21 | import java.io.FileInputStream;
|
---|
22 | import java.io.IOException;
|
---|
23 | import java.io.PrintStream;
|
---|
24 | import org.apache.tools.ant.BuildException;
|
---|
25 | import sun.misc.UUEncoder;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * An emailer that uuencodes attachments.
|
---|
29 | *
|
---|
30 | * @since Ant 1.5
|
---|
31 | */
|
---|
32 | class UUMailer extends PlainMailer {
|
---|
33 | protected void attach(File file, PrintStream out)
|
---|
34 | throws IOException {
|
---|
35 | if (!file.exists() || !file.canRead()) {
|
---|
36 | throw new BuildException("File \"" + file.getName()
|
---|
37 | + "\" does not exist or is not "
|
---|
38 | + "readable.");
|
---|
39 | }
|
---|
40 |
|
---|
41 | FileInputStream finstr = new FileInputStream(file);
|
---|
42 |
|
---|
43 | try {
|
---|
44 | BufferedInputStream in = new BufferedInputStream(finstr);
|
---|
45 | UUEncoder encoder = new UUEncoder(file.getName());
|
---|
46 |
|
---|
47 | encoder.encode(in, out);
|
---|
48 |
|
---|
49 | } finally {
|
---|
50 | finstr.close();
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|