Java Resource Load getResourceAsString(InputStream in)

Here you can find the source of getResourceAsString(InputStream in)

Description

get Resource As String

License

Open Source License

Declaration

private static String getResourceAsString(InputStream in) throws IOException 

Method Source Code

//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());
    }
}

Related

  1. getResourceAsStrem(String name)
  2. getResourceAsString(Class clazz, String name)
  3. getResourceAsString(Class clazz, String resource)
  4. getResourceAsString(Class theClass, String fileName)
  5. getResourceAsString(final String resourceName, final Class caller, final String charset)
  6. getResourceAsString(InputStream resource)
  7. getResourceAsString(String name)
  8. getResourceAsString(String path)
  9. getResourceAsString(String relativePath)