读取文件

@param inputStream
@return
@throws IOException
543326
protected String read(InputStream inputStream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, encoding));
        StringBuffer stringBuffer = new StringBuffer();
        String line = reader.readLine();
        while (line != null) {
            stringBuffer.append(line).append("\n");
            line = reader.readLine();
        }
        return stringBuffer.toString();
    }
877980
public static byte[] inputStreamAsByteArray(InputStream inputStream) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
      byte[] buffer = new byte[16 * 1024];
      int read;
      while((read = inputStream.read(buffer)) > 0) {
        os.write(buffer, 0, read);
      }
      return os.toByteArray();
    } catch (IOException e) {
      throw LOG.unableToReadInputStream(e);
    }
    finally {
      closeSilently(inputStream);
    }
  }
872466
public InputStream getInputStream() throws IOException {
        if (cachedContent == null) {
            cachedContent = mos.getData();
        }
        return new ByteArrayInputStream(cachedContent);
    }
1267355
private byte[] read(InputStream in) throws IOException {
		ByteArrayOutputStream out = new ByteArrayOutputStream(READ_FILE_BASE_SIZE);
		byte[] buffer = new byte[READ_BUFFER_SIZE];
		int count = in.read(buffer);
		while (count != -1) {
			if (count != 0) {
				out.write(buffer, 0, count);
			}
			count = in.read(buffer);
		}
		in.close();
		return out.toByteArray();
	}
255123
public static void dump(InputStream inputStream) throws IOException
  {
    if(!(inputStream instanceof BufferedInputStream)) {
      inputStream = new BufferedInputStream(inputStream);
    }
    try {
      byte[] buffer = new byte[BUFFER_SIZE];
      int length;
      while((length = inputStream.read(buffer)) != -1) {
        System.out.write(buffer, 0, length);
      }
    }
    finally {
      inputStream.close();
    }
  }
187730
public static byte[] readFile(File file) throws IOException
    {
        //create stream to file
        InputStream inputStream=new FileInputStream(file);

        //read data
        byte[] data=IOHelper.readStream(inputStream);

        return data;
    }
878652
public static Map<String, Object> read(InputStream stream)
		throws IOException
	{
		ConfigJsonInput input = new ConfigJsonInput(new InputStreamReader(stream, StandardCharsets.UTF_8));
		return read(input);
	}
113594
public static void toFile(InputStream input, File file) throws IOException {
		OutputStream os = new FileOutputStream(file);
		int bytesRead = 0;
		byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
		while ((bytesRead = input.read(buffer, 0, DEFAULT_BUFFER_SIZE)) != -1) {
			os.write(buffer, 0, bytesRead);
		}
		IOUtils.closeQuietly(os);
		IOUtils.closeQuietly(input);
	}
1075149
public static String readToString(InputStream inputStream, Charset charset) throws IOException {
        return new String(FileCopyUtils.copyToByteArray(inputStream), charset);
    }
1091536
public static String fromStream(InputStream stream) throws IOException {
		if (stream != null) {			
			try {
				Writer writer = new StringWriter();
				Reader reader = new BufferedReader(new InputStreamReader(stream));
				int read;
				while ((read = reader.read()) != -1) {
					writer.write(read);
				}
				return writer.toString();
			} finally {
				try {
					stream.close();
				} catch(IOException e) {
					logger.warn("error closing the input stream", e);
				}
			}			
		}
		return null;
	}
1044942
@Override
    public InputStream getInputStream() throws IOException {
        InputStream inputStream = fileItem.getInputStream();
        return (inputStream != null ? inputStream : new ByteArrayInputStream(new byte[0]));
    }
407673
private static InputStream inputStreamFromFile(String relativePathPrefix, String src) throws IOException {
        File file = getFile(relativePathPrefix, src);
        if (!file.exists()) {
            if (src.length() > 0 && src.charAt(0) == File.separatorChar) {
                file = getFile(relativePathPrefix, src.substring(1));
            }
            if (!file.exists()) {
                file = null;
            }
        } else if (!file.isFile() || !file.canRead()) {
            file = null;
        }
        if (file != null) {
            return new FileInputStream(file);
        }
        return null;
    }
144175
@Override
    public synchronized InputStream getInputStream() throws IOException {
        if (connected == false) {
            // Implicitly open the connection if it has not yet been done so.
            connect();
        }

        Object token = ThreadIdentityManager.runAsServer();
        try {
            if (inputStream == null) {
                if ("".equals(archivePath)) {
                    inputStream = new FileInputStream(urlTargetFile);
                } else {
                    inputStream = new FilterZipFileInputStream(urlTargetFile, archivePath);
                }
            }
        } finally {
            ThreadIdentityManager.reset(token);
        }

        return inputStream;
    }
962106
public int readFrom(InputStream stream) throws IOException {
        int bytesRead = stream.read(buffer);
        if (bytesRead < 0) {
            bytesInBuffer = 0;
        } else {
            bytesInBuffer = bytesRead;
        }
        return bytesRead;
    }
246380
public void load(InputStream inputStream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        StringBuilder out = new StringBuilder();
        String line;

        while ((line = reader.readLine()) != null) {
            out.append(line);
            out.append(System.lineSeparator());
        }

        setScriptText(out.toString());
    }
46080
private void streamToOutput(InputStream inputStream) throws IOException {
    try {
      byte[] buffer = new byte[4096];
      int bytesRead = -1;
      while ((bytesRead = inputStream.read(buffer)) != -1) {
        outputStream.write(buffer, 0, bytesRead);
      }
      outputStream.flush();
    } finally {
      inputStream.close();
    }
  }
178648
@Override
  public InputStream getInputStream()
    throws IOException
  {
    InputStream is = _is;
    _is = null;

    return is;
  }