Here you can find the source of getInputStreamFromFile(File pFile)
Parameter | Description |
---|---|
pFile | file to open |
public static InputStream getInputStreamFromFile(File pFile)
//package com.java2s; /*/*from w w w .jav a 2 s . c om*/ * Copyright 2014 The British Library/SCAPE Project Consortium * Author: William Palmer (William.Palmer@bl.uk) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.zip.GZIPInputStream; public class Main { /** * Gets an InputStream for the contents of a file - if the file is .gz it will return * a stream of the decompressed contents * @param pFile file to open * @return stream (or null) */ public static InputStream getInputStreamFromFile(File pFile) { if (!pFile.exists()) return null; try { return new GZIPInputStream(new FileInputStream(pFile)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block try { return new FileInputStream(pFile); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } return null; } }