Here you can find the source of getInputStream(String url)
Parameter | Description |
---|---|
url | specified url |
java.io.InputStream
public static InputStream getInputStream(String url)
//package com.java2s; /*/* w ww .j a v a2s . co m*/ * File: $RCSfile$ * * Copyright (c) 2005 Wincor Nixdorf International GmbH, * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany * All Rights Reserved. * * This software is the confidential and proprietary information * of Wincor Nixdorf ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered * into with Wincor Nixdorf. */ import java.io.File; import java.io.IOException; import java.io.FileInputStream; import java.io.InputStream; import java.io.ByteArrayInputStream; public class Main { /** * return input stream from specified url * * @param url specified url * @return <code>java.io.InputStream</code> */ public static InputStream getInputStream(String url) { InputStream is = null; if (url != null) { if (url.indexOf(File.separator) != -1) { byte[] infoArray = readFile(url); if (infoArray != null) { is = new ByteArrayInputStream(infoArray); } } else { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(url); } } return is; } /** * read file to byte[] with specified file path * * @param filePath specified file path * @return <code>byte[]</code> file content */ public static byte[] readFile(String filePath) { File infoFile = new File(filePath); byte[] result = null; if (infoFile.exists()) { result = new byte[(int) infoFile.length()]; try { FileInputStream fis = new FileInputStream(infoFile); fis.read(result); fis.close(); } catch (IOException e) { e.printStackTrace(); } } return result; } }