Go has very nice io.Reader
and io.Writer
interfaces, that roughly correspond to java.io.InputStream
and java.io.OutputStream
classes in Java (i.e. io.Reader = stream of bytes, io.Writer = sink for bytes).
I'm wondering, if Go also has some equivalent of java.io.Reader
(stream of characters) and java.io.Writer
(sink for characters) classes.
What I want is to read/write string from/to stream, without thinking about the encoding all the time + support for different encodings than just UTF8 (which is what combination of io.Reader + string typecasting gives me almost for free).
Update: so I guess my description is confusing, and I should have avoided comparison to Java stuff. What I want is something like this:
Reader part, read next 128 bytes, and return Go string by decoding bytes using ISO-8859-2 charset.
stringReader := NewStringReader(reader, "iso-8859-2") stringReader.read(128)
Writer part, convert stuff to UTF16-BE bytes, and write it to the writer:
stringWriter := NewStringWriter(writer, "utf16be") stringWriter.write("馞鮂 擙樲橚 褗褆諓");