Read a Resource-file (eg. Text) to String.

@param _stream
@param _charset
@return the file as string, or null on error
779657
public static String readStringFromResources(InputStream _stream, String _charset) {
        if (_stream == null) {
            LOGGER.error("Error: null-Stream received!");
            return null;
        }

        StringBuilder sb = new StringBuilder(100);

        BufferedReader br;
        try {
            br = new BufferedReader(new InputStreamReader(_stream, _charset));
            for (int c = br.read(); c != -1; c = br.read()) {
                sb.append((char) c);
            }
        } catch (IOException _ex) {
            LOGGER.error("Error while reading resource to string: ", _ex);
        }

        return sb.toString();
    }
124008
public static String readFileToString(@NotNull String resource) {
        try {
            try (Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(resource), "UTF-8"))) {

                Writer writer = new StringWriter();

                char[] buffer = new char[1024];
                int n;
                while ((n = r.read(buffer)) != -1) {
                    writer.write(buffer, 0, n);
                }

                return writer.toString();
            }
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
1032000
public static String readFileBufferedAsString(final File file, final String charset) throws IOException {
		return readInputStreamBufferedAsString(new FileInputStream(file), charset);
	}
552499
public static String read(InputStream in, String charsetName) throws IORuntimeException {
		FastByteArrayOutputStream out = read(in);
		return StrUtil.isBlank(charsetName) ? out.toString() : out.toString(charsetName);
	}
1094053
public Object parse(InputStream inputStream, String charset) {
        if (inputStream == null) {
            throw new IllegalArgumentException("inputStream must not be null");
        }
        if (charset == null) {
            throw new IllegalArgumentException("charset must not be null");
        }

        Object content;
        content = createParser().parse(inputStream, charset);
        return content;
    }
392138
def load_stream(filename):
    """"""
    rawfile = pkg_resources.resource_stream(__name__, filename)
    if six.PY2:
        return rawfile
    return io.TextIOWrapper(rawfile, 'utf-8')
1094261
public static String readResourceToString(@NotNull Class<?> clazz, @NotNull String resource) {
        try {
            try (Reader r = new BufferedReader(new InputStreamReader(clazz.getResourceAsStream(resource), "UTF-8"))) {

                Writer writer = new StringWriter();

                char[] buffer = new char[1024];
                int n;
                while ((n = r.read(buffer)) != -1) {
                    writer.write(buffer, 0, n);
                }

                return writer.toString();
            }
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        }
    }
706662
public static String readInputStreamToString( InputStream inputStream ) {

        try {
            // Create the byte list to hold the data
            List<Byte> bytesList = new ArrayList<Byte>();

            byte b = 0;
            while( (b = (byte) inputStream.read()) != -1 ) {
                bytesList.add(b);
            }
            // Close the input stream and return bytes
            inputStream.close();

            byte[] bArray = new byte[bytesList.size()];
            for( int i = 0; i < bArray.length; i++ ) {
                bArray[i] = bytesList.get(i);
            }

            String file = new String(bArray);
            return file;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
1296657
private static List<Map<String, String>> loadWords(InputStream stream) {
    List<Map<String, String>> list = new ArrayList<>();
    try (
      InputStreamReader isr = new InputStreamReader(stream, FILE_ENCODING);
      BufferedReader br = new BufferedReader(isr);
    ) {
      String line;

      Tokenizer wordTokenizer = new Breton().getWordTokenizer();
      while ((line = br.readLine()) != null) {
        line = line.trim();
        if (line.isEmpty() || line.charAt(0) == '#') { // ignore comments
          continue;
        }
        String[] parts = line.split("=");
        if (parts.length != 2) {
          throw new IOException("Format error in file "
                  + JLanguageTool.getDataBroker().getFromRulesDirAsUrl(FILE_NAME)
                  + ", line: " + line);
        }
        String[] wrongForms = parts[0].split("\\|"); // multiple incorrect forms
        for (String wrongForm : wrongForms) {
          int wordCount = 0;
          List<String> tokens = wordTokenizer.tokenize(wrongForm);
          for (String token : tokens) {
            if (!StringTools.isWhitespace(token)) {
              wordCount++;
            }
          }
          // grow if necessary
          for (int i = list.size(); i < wordCount; i++) {
            list.add(new HashMap<>());
          }
          list.get(wordCount - 1).put(wrongForm, parts[1]);
        }
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    // seal the result (prevent modification from outside this class)
    List<Map<String,String>> result = new ArrayList<>();
    for (Map<String, String> map : list) {
      result.add(Collections.unmodifiableMap(map));
    }
    return Collections.unmodifiableList(result);
  }
1285377
private static String inputStreamToString(InputStream stream)
			throws IOException {
		ByteArrayOutputStream result = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int length;
		String resultString = null;
		while ((length = stream.read(buffer)) != -1) {
			result.write(buffer, 0, length);
		}
		resultString = result.toString("UTF-8");
		return resultString;
	}
1082000
public static BufferedReader asReader(InputStream is, Charset charset) {
		try {
			return new BufferedReader(new InputStreamReader(is, charset.toString()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
364434
private String readFileIntoString(String fileName,  InputStream is) throws IOException {
        FileInputStream stream = null;
        InputStreamReader reader = null;
        try {
            if (is != null) {
                reader = new InputStreamReader(is, charset);
            } else {
                stream = new FileInputStream(fileName);
                reader = new InputStreamReader(stream, charset);
            }
            
            return readStreamIntoString(reader);
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (stream != null) {
                stream.close();
            }
        }
    }
794952
public static String readString(String resourceClasspath,
            String charsetName) {
        return JMInputStream.toString(getResourceInputStream(resourceClasspath),
                charsetName);
    }
914291
public String readString(String charset) throws IOException {
		long len = readInt();

		if (len > available())
			throw new IOException("Cannot read string of length " + len
					+ " bytes when only " + available()
					+ " bytes are available");

		byte[] raw = new byte[(int) len];
		readFully(raw);
		if (encode) {
			return new String(raw, charset);
		}
		return new String(raw);

	}
1140177
private String readResource(final String resourceName) throws IOException {
      return new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(resourceName), DEFAULT_CHARSET)).lines().collect(Collectors.joining("\n"));
   }
866499
public static String readFromFile(final File file, final Charset encoding) throws IOException
	{
		return inputStream2String(StreamExtensions.getInputStream(file), encoding);
	}
989820
private static String readAsString(InputStream stream) throws IOException {
    StringWriter writer = new StringWriter();
    Reader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
    while (true) {
      int c = reader.read();
      if (c < 0) {
        break;
      }
      writer.write(c);
    }
    return writer.toString();
  }