Package java.nio.charset

Examples of java.nio.charset.CharsetDecoder


    final boolean expand = getBoolean("expand", true);
    String synonyms = args.get("synonyms");
    if (synonyms == null)
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Missing required argument 'synonyms'.");

    CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder()
            .onMalformedInput(CodingErrorAction.REPORT)
            .onUnmappableCharacter(CodingErrorAction.REPORT);

    SolrSynonymParser parser = new SolrSynonymParser(dedup, expand, analyzer);
    File synonymFile = new File(synonyms);
    if (synonymFile.exists()) {
      decoder.reset();
      parser.add(new InputStreamReader(loader.openResource(synonyms), decoder));
    } else {
      List<String> files = StrUtils.splitFileNames(synonyms);
      for (String file : files) {
        decoder.reset();
        parser.add(new InputStreamReader(loader.openResource(file), decoder));
      }
    }
    return parser.build();
  }
View Full Code Here


    final boolean expand = getBoolean("expand", true);
    String synonyms = args.get("synonyms");
    if (synonyms == null)
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Missing required argument 'synonyms'.");

    CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder()
            .onMalformedInput(CodingErrorAction.REPORT)
            .onUnmappableCharacter(CodingErrorAction.REPORT);

    WordnetSynonymParser parser = new WordnetSynonymParser(dedup, expand, analyzer);
    File synonymFile = new File(synonyms);
    if (synonymFile.exists()) {
      decoder.reset();
      parser.add(new InputStreamReader(loader.openResource(synonyms), decoder));
    } else {
      List<String> files = StrUtils.splitFileNames(synonyms);
      for (String file : files) {
        decoder.reset();
        parser.add(new InputStreamReader(loader.openResource(file), decoder));
      }
    }
    return parser.build();
  }
View Full Code Here

    return key;
  }

  private String tryDecodeAsString(byte[] data) {
    try {
      CharsetDecoder decoder = Utf8.CHARSET.newDecoder();
      decoder.onMalformedInput(CodingErrorAction.REPORT);
      decoder.onUnmappableCharacter(CodingErrorAction.REPORT);

      ByteBuffer byteBuffer = ByteBuffer.wrap(data);
      CharBuffer charBuffer = decoder.decode(byteBuffer);
      return charBuffer.toString();
    } catch (Exception e) {
      log.debug("Cannot decode as string", e);
      return null;
    }
View Full Code Here

  }

  private String tryDecodeAsString(byte[] data) {
    try {
      // We do this so we get strict input processing
      CharsetDecoder decoder = Charsets.UTF_8.newDecoder();
      decoder.onMalformedInput(CodingErrorAction.REPORT);
      decoder.onUnmappableCharacter(CodingErrorAction.REPORT);

      ByteBuffer byteBuffer = ByteBuffer.wrap(data);
      CharBuffer charBuffer = decoder.decode(byteBuffer);
      return charBuffer.toString();
    } catch (Exception e) {
      log.debug("Cannot decode as string", e);
      return null;
    }
View Full Code Here

    final boolean expand = getBoolean("expand", true);
    String synonyms = args.get("synonyms");
    if (synonyms == null)
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Missing required argument 'synonyms'.");
   
    CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder()
      .onMalformedInput(CodingErrorAction.REPORT)
      .onUnmappableCharacter(CodingErrorAction.REPORT);
   
    SolrSynonymParser parser = new SolrSynonymParser(dedup, expand, analyzer);
    File synonymFile = new File(synonyms);
    if (synonymFile.exists()) {
      decoder.reset();
      parser.add(new InputStreamReader(loader.openResource(synonyms), decoder));
    } else {
      List<String> files = StrUtils.splitFileNames(synonyms);
      for (String file : files) {
        decoder.reset();
        parser.add(new InputStreamReader(loader.openResource(file), decoder));
      }
    }
    return parser.build();
  }
View Full Code Here

    final boolean expand = getBoolean("expand", true);
    String synonyms = args.get("synonyms");
    if (synonyms == null)
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Missing required argument 'synonyms'.");
   
    CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder()
      .onMalformedInput(CodingErrorAction.REPORT)
      .onUnmappableCharacter(CodingErrorAction.REPORT);
   
    WordnetSynonymParser parser = new WordnetSynonymParser(dedup, expand, analyzer);
    File synonymFile = new File(synonyms);
    if (synonymFile.exists()) {
      decoder.reset();
      parser.add(new InputStreamReader(loader.openResource(synonyms), decoder));
    } else {
      List<String> files = StrUtils.splitFileNames(synonyms);
      for (String file : files) {
        decoder.reset();
        parser.add(new InputStreamReader(loader.openResource(file), decoder));
      }
    }
    return parser.build();
  }
View Full Code Here

    Charset charset = Charset.forName("US-ASCII");

    try {
      InputStream in = env.getMessageInputStream();
      byte[] buf = new byte[16384];
      CharsetDecoder decoder = charset.newDecoder();
      int len = 0;
      while ((len = in.read(buf)) >= 0) {
        session.getLogger().trace(decoder.decode(ByteBuffer.wrap(buf, 0, len)).toString());
      }
    } catch (IOException ioex) {
      session.getLogger().debug("Mail data logging failed", ioex);
    }
    }
View Full Code Here

            CharBuffer cb = null;
            if (looksLikeAscii(bytes)) {
                final Charset[] css = { Charsets.UTF_8, Charsets.ISO_8859_1 };
                final Charset[] tryCharsets = css;
                for (final Charset cset : tryCharsets) {
                    final CharsetDecoder cd = cset.newDecoder();
                    cd.onMalformedInput(CodingErrorAction.REPORT);
                    cd.onUnmappableCharacter(CodingErrorAction.REPORT);
                    try {
                        cb = cd.decode(ByteBuffer.wrap(bytes));
                        break;
                    } catch (final CharacterCodingException e) {
                    }
                }
            }
View Full Code Here

            new DataFileStream<GenericRecord>(input, reader);
        GenericRecord record = new GenericData.Record(avroStream.getSchema());
        while (avroStream.hasNext()) {
          avroStream.next(record);
          ByteBuffer body = (ByteBuffer) record.get("body");
          CharsetDecoder decoder = Charsets.UTF_8.newDecoder();
          String bodyStr = decoder.decode(body).toString();
          LOG.debug("Removing event: {}", bodyStr);
          bodies.remove(bodyStr);
          found++;
        }
        avroStream.close();
View Full Code Here

        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);

  // Decode the file into a char buffer
        // Charset and decoder for ISO-8859-15
        Charset charset = Charset.forName("ISO-8859-15");
        CharsetDecoder decoder = charset.newDecoder();
  CharBuffer cb = decoder.decode(bb);

        Matcher matcher = pattern.matcher(cb);
        String outString = matcher.replaceAll(substituteReplacement);
        log.debug(outString);
View Full Code Here

TOP

Related Classes of java.nio.charset.CharsetDecoder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.