本文整理汇总了Java中java.nio.charset.CodingErrorAction.REPORT属性的典型用法代码示例。如果您正苦于以下问题:Java CodingErrorAction.REPORT属性的具体用法?Java CodingErrorAction.REPORT怎么用?Java CodingErrorAction.REPORT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.nio.charset.CodingErrorAction
的用法示例。
在下文中一共展示了CodingErrorAction.REPORT属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: B2CConverter
public B2CConverter(String encoding, boolean replaceOnError)
throws IOException {
byte[] left = new byte[LEFTOVER_SIZE];
leftovers = ByteBuffer.wrap(left);
CodingErrorAction action;
if (replaceOnError) {
action = CodingErrorAction.REPLACE;
} else {
action = CodingErrorAction.REPORT;
}
Charset charset = getCharset(encoding);
// Special case. Use the Apache Harmony based UTF-8 decoder because it
// - a) rejects invalid sequences that the JVM decoder does not
// - b) fails faster for some invalid sequences
if (charset.equals(UTF_8)) {
decoder = new Utf8Decoder();
} else {
decoder = charset.newDecoder();
}
decoder.onMalformedInput(action);
decoder.onUnmappableCharacter(action);
}
示例2: init
/**
* Initializes this session input buffer.
*
* @param instream the source input stream.
* @param buffersize the size of the internal buffer.
* @param params HTTP parameters.
*/
protected void init(final InputStream instream, final int buffersize, final HttpParams params) {
Args.notNull(instream, "Input stream");
Args.notNegative(buffersize, "Buffer size");
Args.notNull(params, "HTTP parameters");
this.instream = instream;
this.buffer = new byte[buffersize];
this.bufferpos = 0;
this.bufferlen = 0;
this.linebuffer = new ByteArrayBuffer(buffersize);
final String charset = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
this.charset = charset != null ? Charset.forName(charset) : Consts.ASCII;
this.ascii = this.charset.equals(Consts.ASCII);
this.decoder = null;
this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512);
this.metrics = createTransportMetrics();
final CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
this.onMalformedCharAction = a1 != null ? a1 : CodingErrorAction.REPORT;
final CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
this.onUnmappableCharAction = a2 != null? a2 : CodingErrorAction.REPORT;
}
示例3: AbstractSessionOutputBuffer
protected AbstractSessionOutputBuffer(
final OutputStream outstream,
final int buffersize,
final Charset charset,
final int minChunkLimit,
final CodingErrorAction malformedCharAction,
final CodingErrorAction unmappableCharAction) {
super();
Args.notNull(outstream, "Input stream");
Args.notNegative(buffersize, "Buffer size");
this.outstream = outstream;
this.buffer = new ByteArrayBuffer(buffersize);
this.charset = charset != null ? charset : Consts.ASCII;
this.ascii = this.charset.equals(Consts.ASCII);
this.encoder = null;
this.minChunkLimit = minChunkLimit >= 0 ? minChunkLimit : 512;
this.metrics = createTransportMetrics();
this.onMalformedCharAction = malformedCharAction != null ? malformedCharAction :
CodingErrorAction.REPORT;
this.onUnmappableCharAction = unmappableCharAction != null? unmappableCharAction :
CodingErrorAction.REPORT;
}
示例4: init
protected void init(final OutputStream outstream, final int buffersize, final HttpParams params) {
Args.notNull(outstream, "Input stream");
Args.notNegative(buffersize, "Buffer size");
Args.notNull(params, "HTTP parameters");
this.outstream = outstream;
this.buffer = new ByteArrayBuffer(buffersize);
final String charset = (String) params.getParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET);
this.charset = charset != null ? Charset.forName(charset) : Consts.ASCII;
this.ascii = this.charset.equals(Consts.ASCII);
this.encoder = null;
this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512);
this.metrics = createTransportMetrics();
final CodingErrorAction a1 = (CodingErrorAction) params.getParameter(
CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
this.onMalformedCharAction = a1 != null ? a1 : CodingErrorAction.REPORT;
final CodingErrorAction a2 = (CodingErrorAction) params.getParameter(
CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
this.onUnmappableCharAction = a2 != null? a2 : CodingErrorAction.REPORT;
}
示例5: getDecoder
public CharsetDecoder getDecoder(String encodingName, boolean ignoreEncodingErrors) {
Charset cs = (this.charset == null)
? Charset.forName(encodingName)
: this.charset;
CharsetDecoder decoder = cs.newDecoder();
CodingErrorAction action;
if (ignoreEncodingErrors)
action = CodingErrorAction.REPLACE;
else
action = CodingErrorAction.REPORT;
return decoder
.onMalformedInput(action)
.onUnmappableCharacter(action);
}
示例6: B2CConverter
public B2CConverter(String encoding, boolean replaceOnError) throws IOException {
byte[] left = new byte[LEFTOVER_SIZE];
leftovers = ByteBuffer.wrap(left);
CodingErrorAction action;
if (replaceOnError) {
action = CodingErrorAction.REPLACE;
} else {
action = CodingErrorAction.REPORT;
}
Charset charset = getCharset(encoding);
// Special case. Use the Apache Harmony based UTF-8 decoder because it
// - a) rejects invalid sequences that the JVM decoder does not
// - b) fails faster for some invalid sequences
if (charset.equals(UTF_8)) {
decoder = new Utf8Decoder();
} else {
decoder = charset.newDecoder();
}
decoder.onMalformedInput(action);
decoder.onUnmappableCharacter(action);
}
示例7: getMalformedInputAction
/**
* Obtains value of the {@link CoreProtocolPNames#HTTP_MALFORMED_INPUT_ACTION} parameter.
* @param params HTTP parameters.
* @return Action to perform upon receiving a malformed input
*
* @since 4.2
*/
public static CodingErrorAction getMalformedInputAction(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Object param = params.getParameter(CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
if (param == null) {
// the default CodingErrorAction
return CodingErrorAction.REPORT;
}
return (CodingErrorAction) param;
}
示例8: getUnmappableInputAction
/**
* Obtains the value of the {@link CoreProtocolPNames#HTTP_UNMAPPABLE_INPUT_ACTION} parameter.
* @param params HTTP parameters
* @return Action to perform upon receiving a unmapped input
*
* @since 4.2
*/
public static CodingErrorAction getUnmappableInputAction(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Object param = params.getParameter(CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
if (param == null) {
// the default CodingErrorAction
return CodingErrorAction.REPORT;
}
return (CodingErrorAction) param;
}
示例9: getMalformedInputAction
/**
* Obtains value of the {@link CoreProtocolPNames#HTTP_MALFORMED_INPUT_ACTION} parameter.
* @param params HTTP parameters.
* @return Action to perform upon receiving a malformed input
*
* @since 4.2
*/
public static CodingErrorAction getMalformedInputAction(final HttpParams params) {
Args.notNull(params, "HTTP parameters");
final Object param = params.getParameter(CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION);
if (param == null) {
// the default CodingErrorAction
return CodingErrorAction.REPORT;
}
return (CodingErrorAction) param;
}
示例10: getUnmappableInputAction
/**
* Obtains the value of the {@link CoreProtocolPNames#HTTP_UNMAPPABLE_INPUT_ACTION} parameter.
* @param params HTTP parameters
* @return Action to perform upon receiving a unmapped input
*
* @since 4.2
*/
public static CodingErrorAction getUnmappableInputAction(final HttpParams params) {
Args.notNull(params, "HTTP parameters");
final Object param = params.getParameter(CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION);
if (param == null) {
// the default CodingErrorAction
return CodingErrorAction.REPORT;
}
return (CodingErrorAction) param;
}
示例11: create
public ManagedHttpClientConnection create(final HttpRoute route, final ConnectionConfig config) {
final ConnectionConfig cconfig = config != null ? config : ConnectionConfig.DEFAULT;
CharsetDecoder chardecoder = null;
CharsetEncoder charencoder = null;
final Charset charset = cconfig.getCharset();
final CodingErrorAction malformedInputAction = cconfig.getMalformedInputAction() != null ?
cconfig.getMalformedInputAction() : CodingErrorAction.REPORT;
final CodingErrorAction unmappableInputAction = cconfig.getUnmappableInputAction() != null ?
cconfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
if (charset != null) {
chardecoder = charset.newDecoder();
chardecoder.onMalformedInput(malformedInputAction);
chardecoder.onUnmappableCharacter(unmappableInputAction);
charencoder = charset.newEncoder();
charencoder.onMalformedInput(malformedInputAction);
charencoder.onUnmappableCharacter(unmappableInputAction);
}
final String id = "http-outgoing-" + Long.toString(COUNTER.getAndIncrement());
return new LoggingManagedHttpClientConnection(
id,
log,
headerlog,
wirelog,
cconfig.getBufferSize(),
cconfig.getFragmentSizeHint(),
chardecoder,
charencoder,
cconfig.getMessageConstraints(),
null,
null,
requestWriterFactory,
responseParserFactory);
}
示例12: ResettableFileInputStream
/**
*
* @param file
* File to read
*
* @param tracker
* PositionTracker implementation to make offset position durable
*
* @param bufSize
* Size of the underlying buffer used for input. If lesser than {@link #MIN_BUF_SIZE},
* a buffer of length {@link #MIN_BUF_SIZE} will be created instead.
*
* @param charset
* Character set used for decoding text, as necessary
*
* @param decodeErrorPolicy
* A {@link DecodeErrorPolicy} instance to determine how
* the decoder should behave in case of malformed input and/or
* unmappable character.
*
* @throws FileNotFoundException If the file to read does not exist
* @throws IOException If the position reported by the tracker cannot be sought
*/
public ResettableFileInputStream(File file, PositionTracker tracker,
int bufSize, Charset charset, DecodeErrorPolicy decodeErrorPolicy)
throws IOException {
this.file = file;
this.tracker = tracker;
this.in = new FileInputStream(file);
this.chan = in.getChannel();
this.buf = ByteBuffer.allocateDirect(Math.max(bufSize, MIN_BUF_SIZE));
buf.flip();
this.byteBuf = new byte[1]; // single byte
this.charBuf = CharBuffer.allocate(2); // two chars for surrogate pairs
charBuf.flip();
this.fileSize = file.length();
this.decoder = charset.newDecoder();
this.position = 0;
this.syncPosition = 0;
if (charset.name().startsWith("UTF-8")) {
// some JDKs wrongly report 3 bytes max
this.maxCharWidth = 4;
} else if (charset.name().startsWith("UTF-16")) {
// UTF_16BE and UTF_16LE wrongly report 2 bytes max
this.maxCharWidth = 4;
} else if (charset.name().startsWith("UTF-32")) {
// UTF_32BE and UTF_32LE wrongly report 4 bytes max
this.maxCharWidth = 8;
} else {
this.maxCharWidth = (int) Math.ceil(charset.newEncoder().maxBytesPerChar());
}
CodingErrorAction errorAction;
switch (decodeErrorPolicy) {
case FAIL:
errorAction = CodingErrorAction.REPORT;
break;
case REPLACE:
errorAction = CodingErrorAction.REPLACE;
break;
case IGNORE:
errorAction = CodingErrorAction.IGNORE;
break;
default:
throw new IllegalArgumentException(
"Unexpected value for decode error policy: " + decodeErrorPolicy);
}
decoder.onMalformedInput(errorAction);
decoder.onUnmappableCharacter(errorAction);
seek(tracker.getPosition());
}