All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.laamella.sexpression.CharSource Maven / Gradle / Ivy

There is a newer version: 0.2
Show newest version
package com.laamella.sexpression;

import java.io.*;
import java.nio.charset.Charset;

public class CharSource {
	public static Charset UTF8 = Charset.forName("utf-8");

	public static  void push(Reader reader, T charSink) throws IOException {
		while (true) {
			int c = reader.read();
			if (c == -1) {
				charSink.close();
				return;
			}
			charSink.accept((char) c);
		}
	}

	public static  void pushResource(String resourceName, Charset encoding, T charSink) throws IOException {
		try (
				InputStream resourceAsStream = CharSource.class.getResourceAsStream(resourceName);
				InputStreamReader reader = new InputStreamReader(resourceAsStream, encoding);
		) {
			push(reader, charSink);
		}
	}

	public static  void pushString(String string, T charSink) throws IOException {
		push(new StringReader(string), charSink);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy