KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > util > PropertyOutputStream


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.util;
20
21 import java.io.ByteArrayOutputStream JavaDoc;
22
23 import org.apache.tools.ant.Project;
24
25 /**
26  * Exception thrown when an attempt is made to get an OutputStream
27  * from an immutable Resource.
28  * @since Ant 1.7
29  */

30 public class PropertyOutputStream extends ByteArrayOutputStream JavaDoc {
31     private Project project;
32     private String JavaDoc property;
33     private boolean trim;
34
35     /**
36      * Construct a new PropertyOutputStream for the specified Project
37      * and property name, trimming the property value.
38      * @param p the associated Ant Project.
39      * @param s the String property name.
40      */

41     public PropertyOutputStream(Project p, String JavaDoc s) {
42         this(p, s, true);
43     }
44
45     /**
46      * Construct a new PropertyOutputStream for
47      * the specified Project, property name, and trim mode.
48      * @param p the associated Ant Project.
49      * @param s the String property name.
50      * @param b the boolean trim mode.
51      */

52     public PropertyOutputStream(Project p, String JavaDoc s, boolean b) {
53         project = p;
54         property = s;
55         trim = b;
56     }
57
58     /**
59      * Close the PropertyOutputStream, storing the property.
60      */

61     public void close() {
62         if (project != null && property != null) {
63             String JavaDoc s = new String JavaDoc(toByteArray());
64             project.setNewProperty(property, trim ? s.trim() : s);
65         }
66     }
67
68 }
69
70
Popular Tags