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 * @author ribnitz 12 * 13 */ 14 public class InputStreamFactory { 15 16 /** 17 * Create a Stream to read from the given fˇile 18 * @param f - the file to read from 19 * @return 20 * @throws FileNotFoundException - if the File does not exist 21 * @throws SecurityException - if a security manager exists and its checkRead method denies read access to the file 22 */ createInputStream(File f)23 public static InputStream createInputStream(File f) throws FileNotFoundException { 24 FileInputStream fis = new FileInputStream(f); 25 return InputStreamFactory.buffer(fis); 26 } 27 28 /** 29 * Decorate another InputStream to create a Buffering version 30 * @param in -the Stream to decorate 31 * @return a buffered version of the stream 32 */ buffer(InputStream in)33 public static InputStream buffer(InputStream in) { 34 if (in instanceof BufferedInputStream) { 35 return in; 36 } 37 return new BufferedInputStream(in); 38 } 39 40 } 41