Package org.gjt.sp.jedit.io
Class RegexEncodingDetector
- java.lang.Object
-
- org.gjt.sp.jedit.io.RegexEncodingDetector
-
- All Implemented Interfaces:
EncodingDetector
public class RegexEncodingDetector extends java.lang.Object implements EncodingDetector
An encoding detector which finds regex pattern. This reads the sample in the system default encoding for first some lines and look for a regex pattern. This can fail if the stream cannot be read in the system default encoding or the pattern is not found at near the top of the stream.- Since:
- 4.3pre16
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
VALID_ENCODING_PATTERN
A regex pattern matches to "Charset names" specified for java.nio.charset.Charset.
-
Constructor Summary
Constructors Constructor Description RegexEncodingDetector(java.lang.String pattern, java.lang.String replacement)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
detectEncoding(java.io.InputStream sample)
Detects the encoding of the given sample.java.lang.String
toString()
-
-
-
Field Detail
-
VALID_ENCODING_PATTERN
public static final java.lang.String VALID_ENCODING_PATTERN
A regex pattern matches to "Charset names" specified for java.nio.charset.Charset.- See Also:
- Charset names, Constant Field Values
-
-
Method Detail
-
detectEncoding
@Nullable public java.lang.String detectEncoding(java.io.InputStream sample) throws java.io.IOException
Detects the encoding of the given sample. The sample input stream must not be closed in this method- Specified by:
detectEncoding
in interfaceEncodingDetector
- Parameters:
sample
- the sample input stream- Returns:
- the detected encoding or null if the encoding cannot be detected
- Throws:
java.io.IOException
- if an I/O error occurs
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-