• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java DecodeErrorPolicy类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.apache.flume.serialization.DecodeErrorPolicy的典型用法代码示例。如果您正苦于以下问题:Java DecodeErrorPolicy类的具体用法?Java DecodeErrorPolicy怎么用?Java DecodeErrorPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

DecodeErrorPolicy类属于org.apache.flume.serialization包,在下文中一共展示了DecodeErrorPolicy类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: ResettableFileInputStream1

点赞 2

import org.apache.flume.serialization.DecodeErrorPolicy; //导入依赖的package包/类
/**
 *
 * @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 ResettableFileInputStream1(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());
}
 

开发者ID:feiyuyitiao,
项目名称:flume-ng-extends,
代码行数:73,
代码来源:ResettableFileInputStream1.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)