View Javadoc
1 // $Id: FileInput.java,v 1.1 2004/02/12 22:38:15 powerpete Exp $ 2 // [JMP, 12.02.2004] Created this file. 3 package org.jface.stepmt.demoapp.files; 4 5 import java.io.BufferedInputStream; 6 import java.io.ByteArrayOutputStream; 7 import java.io.FileInputStream; 8 import java.io.IOException; 9 import java.io.InputStream; 10 import java.io.OutputStream; 11 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 15 /*** 16 * @author <a href="mailto:powerpete@users.sf.net">M. Petersen</a> 17 * @version $Id: FileInput.java,v 1.1 2004/02/12 22:38:15 powerpete Exp $ 18 */ 19 public class FileInput 20 { 21 private static final Log LOG = LogFactory.getLog(FileInput.class); 22 23 public String read(String filename) 24 { 25 InputStream in = null; 26 OutputStream out = null; 27 try 28 { 29 in = new BufferedInputStream(new FileInputStream(filename)); 30 out = new ByteArrayOutputStream(); 31 int length = 0; 32 byte[] bytes = new byte[1024 * 32]; 33 while ((length = in.read(bytes)) != -1) 34 { 35 out.write(bytes, 0, length); 36 } 37 } 38 catch (IOException e) 39 { 40 LOG.fatal("Error while reading file " + filename, e); 41 return null; 42 } 43 finally 44 { 45 try 46 { 47 in.close(); 48 } 49 catch (IOException e) 50 { 51 // GIVE UP. 52 } 53 } 54 return out.toString(); 55 } 56 }

This page was automatically generated by Maven