public abstract class AbstractCharactersetFinder extends Object implements CharactersetFinder
Constructor and Description |
---|
AbstractCharactersetFinder() |
Modifier and Type | Method and Description |
---|---|
Charset |
detectCharset(byte[] buffer)
Attempt to detect the character set encoding for the given buffer.
|
Charset |
detectCharset(InputStream is)
Attempt to detect the character set encoding for the give input stream.
|
protected abstract Charset |
detectCharsetImpl(byte[] buffer)
Worker method for implementations to override.
|
protected int |
getBufferSize()
Some implementations may only require a few bytes to do detect the stream type,
whilst others may be more efficient with larger buffers.
|
void |
setBufferSize(int bufferSize)
Set the maximum number of bytes to read ahead when attempting to determine the characterset.
|
public void setBufferSize(int bufferSize)
bufferSize
- the number of bytes - default 8K.public final Charset detectCharset(InputStream is)
BufferedInputStream
.
The current state of the stream will be restored before the method returns.
The input stream is checked to ensure that it supports marks, after which a buffer is extracted, leaving the stream in its original state.
detectCharset
in interface CharactersetFinder
is
- an input stream that must support markingpublic final Charset detectCharset(byte[] buffer)
CharactersetFinder
detectCharset
in interface CharactersetFinder
buffer
- the first n bytes of the character streamprotected int getBufferSize()
Only override this method if there is a very compelling reason to adjust the buffer
size, and then consider handling the setBufferSize(int)
method by issuing a
warning. This will prevent users from setting the buffer size when it has no effect.
CharactersetFinder.detectCharset(byte[])
method.setBufferSize(int)
protected abstract Charset detectCharsetImpl(byte[] buffer) throws Exception
The interface contract is that the data buffer must not be altered in any way.
buffer
- the buffer of data no bigger than the requested
best buffer size. This can,
very efficiently, be turned into an InputStream using a
ByteArrayInputStream.Exception
- Any exception, checked or notCopyright © 2005–2020 Alfresco Software. All rights reserved.