X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fparsing%2Futils%2FLaxUTF8Reader.java;h=96e1bae72dc15a16b4238808c7c82a7f3350edf9;hb=3ccd513530bc718ef384780d3151ddbb85600986;hp=c9f28ef012feb0253cc19c73ac613ca95a8c8ab0;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/utils/LaxUTF8Reader.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/utils/LaxUTF8Reader.java index c9f28ef01..96e1bae72 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/utils/LaxUTF8Reader.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/utils/LaxUTF8Reader.java @@ -1,41 +1,41 @@ -package org.simantics.scl.compiler.internal.parsing.utils; - -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CodingErrorAction; - -public class LaxUTF8Reader extends InputStreamReader { - private static final Charset UTF8 = Charset.forName("UTF-8"); - private static final CharsetDecoder UTF8_DECODER = UTF8.newDecoder(); - - static { - UTF8_DECODER.onMalformedInput(CodingErrorAction.REPLACE); - UTF8_DECODER.onUnmappableCharacter(CodingErrorAction.REPLACE); - UTF8_DECODER.replaceWith("\ufffd"); - } - - /** - * Skips possible BOM (ef bb bf) in the beginning of the stream. - */ - private static BufferedInputStream skipBOM(BufferedInputStream stream) throws IOException { - stream.mark(4); - if(stream.read() == 0xef) - if(stream.read() == 0xbb) - if(stream.read() == 0xbf) - return stream; - stream.reset(); - return stream; - } - - public LaxUTF8Reader(BufferedInputStream stream) throws IOException { - super(skipBOM(stream), UTF8_DECODER); - } - - public LaxUTF8Reader(String fileName) throws IOException { - this(new BufferedInputStream(new FileInputStream(fileName))); - } -} +package org.simantics.scl.compiler.internal.parsing.utils; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CodingErrorAction; + +public class LaxUTF8Reader extends InputStreamReader { + private static final Charset UTF8 = Charset.forName("UTF-8"); + private static final CharsetDecoder UTF8_DECODER = UTF8.newDecoder(); + + static { + UTF8_DECODER.onMalformedInput(CodingErrorAction.REPLACE); + UTF8_DECODER.onUnmappableCharacter(CodingErrorAction.REPLACE); + UTF8_DECODER.replaceWith("\ufffd"); + } + + /** + * Skips possible BOM (ef bb bf) in the beginning of the stream. + */ + private static BufferedInputStream skipBOM(BufferedInputStream stream) throws IOException { + stream.mark(4); + if(stream.read() == 0xef) + if(stream.read() == 0xbb) + if(stream.read() == 0xbf) + return stream; + stream.reset(); + return stream; + } + + public LaxUTF8Reader(BufferedInputStream stream) throws IOException { + super(skipBOM(stream), UTF8_DECODER); + } + + public LaxUTF8Reader(String fileName) throws IOException { + this(new BufferedInputStream(new FileInputStream(fileName))); + } +}