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.FileNotFoundException;
23 import java.io.UnsupportedEncodingException;
24
25 /**
26 * Wrapper for an input file.
27 *
28 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
29 */
30 public class InputFileWrapper
31 extends AbstractFileWrapper
32 {
33 /** serialVersionUID */
34 static final long serialVersionUID = 6510443036267371188L;
35
36 /**
37 * Private constructor.
38 *
39 * @param absolutePath not null
40 * @param format could be null
41 * @param charsetName could be null
42 * @param supportedFormat not null
43 * @throws UnsupportedEncodingException if the encoding is unsupported.
44 * @throws FileNotFoundException if the file for absolutePath is not found.
45 */
46 private InputFileWrapper( String absolutePath, String format, String charsetName, String[] supportedFormat )
47 throws UnsupportedEncodingException, FileNotFoundException
48 {
49 super( absolutePath, format, charsetName, supportedFormat );
50
51 if ( !getFile().exists() )
52 {
53 throw new FileNotFoundException( "The file '" + getFile().getAbsolutePath() + "' doesn't exist." );
54 }
55 }
56
57 /**
58 * @param absolutePath for a file or a directory not null.
59 * @param format could be null
60 * @param supportedFormat not null
61 * @return a type safe input reader
62 * @throws UnsupportedEncodingException if the encoding is unsupported.
63 * @throws FileNotFoundException if the file for absolutePath is not found.
64 * @see #valueOf(String, String, String, String[]) using AUTO_FORMAT
65 */
66 public static InputFileWrapper valueOf( String absolutePath, String format, String[] supportedFormat )
67 throws UnsupportedEncodingException, FileNotFoundException
68 {
69 return valueOf( absolutePath, format, AUTO_FORMAT, supportedFormat );
70 }
71
72 /**
73 * @param absolutePath for a wanted file or a wanted directory, not null.
74 * @param format could be null
75 * @param charsetName could be null
76 * @param supportedFormat not null
77 * @return a type safe input reader
78 * @throws UnsupportedEncodingException if the encoding is unsupported.
79 * @throws FileNotFoundException if the file for absolutePath is not found.
80 */
81 public static InputFileWrapper valueOf( String absolutePath, String format, String charsetName,
82 String[] supportedFormat )
83 throws UnsupportedEncodingException, FileNotFoundException
84 {
85 return new InputFileWrapper( absolutePath, format, charsetName, supportedFormat );
86 }
87 }