Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
OutputStreamWrapper |
|
| 2.5;2,5 |
1 | package org.apache.maven.doxia.wrapper; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.OutputStream; | |
23 | ||
24 | import org.codehaus.plexus.util.StringUtils; | |
25 | ||
26 | /** | |
27 | * Wrapper for an output stream. | |
28 | * | |
29 | * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> | |
30 | * @version $Id: OutputStreamWrapper.java 786981 2009-06-21 10:01:58Z ltheussl $ | |
31 | */ | |
32 | public class OutputStreamWrapper | |
33 | extends AbstractWrapper | |
34 | { | |
35 | /** serialVersionUID */ | |
36 | static final long serialVersionUID = 3329037527245430610L; | |
37 | ||
38 | private OutputStream out; | |
39 | ||
40 | private String encoding; | |
41 | ||
42 | /** | |
43 | * Private constructor. | |
44 | * | |
45 | * @param format not null | |
46 | * @param supportedFormat not null | |
47 | * @throws IllegalArgumentException if any. | |
48 | */ | |
49 | private OutputStreamWrapper( OutputStream out, String format, String encoding, String[] supportedFormat ) | |
50 | { | |
51 | 0 | super( format, supportedFormat ); |
52 | ||
53 | 0 | if ( getFormat().equalsIgnoreCase( AUTO_FORMAT ) ) |
54 | { | |
55 | 0 | throw new IllegalArgumentException( "output format is required" ); |
56 | } | |
57 | ||
58 | 0 | this.out = out; |
59 | 0 | this.encoding = encoding; |
60 | 0 | } |
61 | ||
62 | /** | |
63 | * @return the output stream | |
64 | */ | |
65 | public OutputStream getOutputStream() | |
66 | { | |
67 | 0 | return this.out; |
68 | } | |
69 | ||
70 | /** | |
71 | * @return the encoding | |
72 | */ | |
73 | public String getEncoding() | |
74 | { | |
75 | 0 | return encoding; |
76 | } | |
77 | ||
78 | /** | |
79 | * @param out not null | |
80 | * @param format not null | |
81 | * @param encoding not null | |
82 | * @param supportedFormat not null | |
83 | * @return a type safe output stream wrapper | |
84 | */ | |
85 | public static OutputStreamWrapper valueOf( OutputStream out, String format, String encoding, | |
86 | String[] supportedFormat ) | |
87 | { | |
88 | 0 | if ( out == null ) |
89 | { | |
90 | 0 | throw new IllegalArgumentException( "output writer is required" ); |
91 | } | |
92 | 0 | if ( StringUtils.isEmpty( format ) ) |
93 | { | |
94 | 0 | throw new IllegalArgumentException( "output format is required" ); |
95 | } | |
96 | ||
97 | 0 | return new OutputStreamWrapper( out, format, encoding, supportedFormat ); |
98 | } | |
99 | } |