Retrieves a string from an input stream. @param stream The input stream. @return The string.
(@Nullable InputStream stream)
| 250 | * @return The string. |
| 251 | */ |
| 252 | public static String readFromInputStream(@Nullable InputStream stream) { |
| 253 | if(stream == null) return "empty"; |
| 254 | |
| 255 | StringBuilder stringBuilder = new StringBuilder(); |
| 256 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) { |
| 257 | String line; while ((line = reader.readLine()) != null) { |
| 258 | stringBuilder.append(line); |
| 259 | } stream.close(); |
| 260 | } catch (IOException e) { |
| 261 | Grasscutter.getLogger().warn("Failed to read from input stream."); |
| 262 | } catch (NullPointerException ignored) { |
| 263 | return "empty"; |
| 264 | } return stringBuilder.toString(); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Performs a linear interpolation using a table of fixed points to create an effective piecewise f(x) = y function. |