Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StreamableFileNameResource |
|
| 1.0;1 |
1 | /** | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | package org.apache.creadur.whisker.app.load; | |
20 | ||
21 | import java.io.BufferedInputStream; | |
22 | import java.io.File; | |
23 | import java.io.FileInputStream; | |
24 | import java.io.IOException; | |
25 | import java.io.InputStream; | |
26 | ||
27 | import org.apache.creadur.whisker.app.StreamableResource; | |
28 | /** | |
29 | * Streams, on demand, the contents of a file identified by a full file name, | |
30 | * including path. | |
31 | */ | |
32 | public class StreamableFileNameResource extends StreamableResource { | |
33 | /** The full file name, including path, of the resource to be streamed */ | |
34 | private final String fileName; | |
35 | ||
36 | /** | |
37 | * Constructs an instance that streams the resource identified by name on demand | |
38 | * @param fileName, full file name, including path, of the resource to be streamed | |
39 | * on demand, not null | |
40 | */ | |
41 | public StreamableFileNameResource(String fileName) { | |
42 | 0 | super(); |
43 | 0 | this.fileName = fileName; |
44 | 0 | } |
45 | ||
46 | /** | |
47 | * Gets the file name of the resource to be streamed. | |
48 | * @return full file name, not null | |
49 | */ | |
50 | public String getFileName() { | |
51 | 0 | return fileName; |
52 | } | |
53 | ||
54 | /** | |
55 | * @see StreamableResource#open() | |
56 | */ | |
57 | @Override | |
58 | public InputStream open() throws IOException { | |
59 | 0 | return new BufferedInputStream(new FileInputStream(new File(fileName))); |
60 | } | |
61 | ||
62 | @Override | |
63 | public String toString() { | |
64 | 0 | return "StreamableFileNameResource [fileName=" + fileName + "]"; |
65 | } | |
66 | } |