Here you can find the source of getResourceAsString(InputStream in)
private static String getResourceAsString(InputStream in) throws IOException
//package com.java2s; /**/*from w w w . j a v a2 s. c o m*/ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com * * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.md file. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { private static String getResourceAsString(InputStream in) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); byte[] buf = new byte[1024]; int sz = 0; try { while (true) { sz = in.read(buf); baos.write(buf, 0, sz); if (sz < buf.length) break; } } finally { try { in.close(); } catch (Exception e) { } } return new String(baos.toByteArray()); } }