• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.unicode.cldr.util;
2 
3 import java.io.BufferedInputStream;
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.FileNotFoundException;
7 import java.io.InputStream;
8 
9 /**
10  * Factory class to easily create (buffered) InputStreams
11  *
12  * @author ribnitz
13  */
14 public class InputStreamFactory {
15 
16     /**
17      * Create a Stream to read from the given fˇile
18      *
19      * @param f - the file to read from
20      * @return
21      * @throws FileNotFoundException - if the File does not exist
22      * @throws SecurityException - if a security manager exists and its checkRead method denies read
23      *     access to the file
24      */
createInputStream(File f)25     public static InputStream createInputStream(File f) throws FileNotFoundException {
26         FileInputStream fis = new FileInputStream(f);
27         return InputStreamFactory.buffer(fis);
28     }
29 
30     /**
31      * Decorate another InputStream to create a Buffering version
32      *
33      * @param in -the Stream to decorate
34      * @return a buffered version of the stream
35      */
buffer(InputStream in)36     public static InputStream buffer(InputStream in) {
37         if (in instanceof BufferedInputStream) {
38             return in;
39         }
40         return new BufferedInputStream(in);
41     }
42 }
43