Package java.nio.charset

Examples of java.nio.charset.Charset$IgnoreCaseComparator


            FileInputStream input = new FileInputStream(file);
            FileChannel channel = input.getChannel();
            long fileLength = channel.size();
            MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength);
            // character buffer
            Charset charset = java.nio.charset.Charset.forName("UTF-8");
            CharsetDecoder decoder = charset.newDecoder();
            return decoder.decode(buffer);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
View Full Code Here


  private HttpPost composeMultiPartFormRequest(final String uri, final Parameters parameters, final Map<String, ContentBody> files) {
    HttpPost request = new HttpPost(uri);
    MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

    try {
      Charset utf8 = Charset.forName("UTF-8");
      for(Parameter param : parameters)
        if(param.isSingleValue())
          multiPartEntity.addPart(param.getName(), new StringBody(param.getValue(), utf8));
        else
          for(String value : param.getValues())
View Full Code Here

  }

  @Test
  public void testMessageParsing() {
    SyslogParser parser = new SyslogParser();
    Charset charset = Charsets.UTF_8;
    List<String> messages = Lists.newArrayList();

    // supported examples from RFC 3164
    messages.add("<34>Oct 11 22:14:15 mymachine su: 'su root' failed for " +
        "lonvick on /dev/pts/8");
View Full Code Here

        String portStr = entry.getKey();
        String charsetStr = entry.getValue();
        Integer port = Integer.parseInt(portStr);
        Preconditions.checkNotNull(port, "Invalid port number in config");
        try {
          Charset charset = Charset.forName(charsetStr);
          portCharsets.put(port, new ThreadSafeDecoder(charset));
        } catch (Exception ex) {
          throw new IllegalArgumentException("Unable to parse charset " +
              "string (" + charsetStr + ") from port configuration.", ex);
        }
View Full Code Here

  CodeGenerator(
      CodeConsumer consumer,
      CompilerOptions options) {
    cc = consumer;

    Charset outputCharset = options.getOutputCharset();
    if (outputCharset == null || outputCharset == US_ASCII) {
      // If we want our default (pretending to be UTF-8, but escaping anything
      // outside of straight ASCII), then don't use the encoder, but
      // just special-case the code.  This keeps the normal path through
      // the code identical to how it's been for years.
      this.outputCharsetEncoder = null;
    } else {
      this.outputCharsetEncoder = outputCharset.newEncoder();
    }
    this.preferSingleQuotes = options.preferSingleQuotes;
    this.trustedStrings = options.trustedStrings;
    this.languageMode = options.getLanguageOut();
    this.preserveTypeAnnotations = options.preserveTypeAnnotations;
View Full Code Here

  private static Reader removeBOM(InputStream in, String encoding) throws IOException {
    byte[] detectionBuffer = new byte[UnicodeDetector.getMaximumBOMLength()];
    int bufferSize = in.read(detectionBuffer);
    ByteOrderMarker b = UnicodeDetector.detectBom(detectionBuffer, bufferSize);
    if (b != null) {
      Charset ref = Charset.forName(encoding);
      if (UnicodeDetector.isAmbigiousBOM(b.getCharset(), ref)) {
        b = ByteOrderMarker.fromString(encoding);
      }
      if (b.getCharset().equals(ref) || b.getGroup().equals(ref)) {
        InputStream prefix = new ByteArrayInputStream(detectionBuffer, b.getHeaderLength(), bufferSize - b.getHeaderLength());
View Full Code Here

    if (b != null) {
      // we have to remove the BOM from the front
      InputStream prefix = new ByteArrayInputStream(detectionBuffer, b.getHeaderLength(), bufferSize - b.getHeaderLength());
      return new InputStreamReader(new ConcatInputStream(prefix, in), b.getCharset());
    }
    Charset cs = UnicodeDetector.detectByContent(detectionBuffer, bufferSize);
    if (cs == null) {
      cs = Charset.defaultCharset();
    }
    InputStream prefix = new ByteArrayInputStream(detectionBuffer, 0, bufferSize);
    return new InputStreamReader(new ConcatInputStream(prefix, in), cs);
View Full Code Here

  public IValue readFile(ISourceLocation sloc, RascalExecutionContext rex){
    sloc = rex.resolveSourceLocation(sloc);
    Reader reader = null;

    try {
      Charset c = rex.getResolverRegistry().getCharset(sloc.getURI());
      if (c != null) {
        return readFileEnc(sloc, values.string(c.name()), rex);
      }
      sloc = rex.resolveSourceLocation(sloc);
      reader = rex.getResolverRegistry().getCharacterReader(sloc.getURI());
      return consumeInputStream(sloc, reader, rex);
    } catch(FileNotFoundException e){
View Full Code Here

    IString charset = values.string("UTF8");
    if (append) {
      // in case the file already has a encoding, we have to correctly append that.
      InputStream in = null;
      Charset detected = null;
      try {
        detected = rex.getResolverRegistry().getCharset(sloc.getURI());
        if (detected == null) {
          in = rex.getResolverRegistry().getInputStream(sloc.getURI());
          detected = UnicodeDetector.estimateCharset(in);
        }
      }catch(FileNotFoundException fnfex){
        throw RuntimeExceptionFactory.pathNotFound(sloc, null, null);
      } catch (IOException e) {
        throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
      }
      finally {
        if (in != null) {
          try {
            in.close();
          } catch (IOException e) {
            throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
          }
        }
      }
      if (detected != null)
        charset = values.string(detected.name());
      else {
        charset = values.string(Charset.defaultCharset().name());
      }
    }
    writeFileEnc(sloc, charset, V, append, rex);
View Full Code Here

  public IList readFileLines(ISourceLocation sloc, RascalExecutionContext rex){
      sloc = rex.resolveSourceLocation(sloc);
      Reader reader = null;
     
      try {
        Charset detected = rex.getResolverRegistry().getCharset(sloc.getURI());
        if (detected != null) {
          return readFileLinesEnc(sloc, values.string(detected.name()), rex);
        }
        reader = rex.getResolverRegistry().getCharacterReader(sloc.getURI());
        return consumeInputStreamLines(sloc, reader, rex);
      }catch(MalformedURLException e){
          throw RuntimeExceptionFactory.malformedURI(sloc.toString(), null, null);
View Full Code Here

TOP

Related Classes of java.nio.charset.Charset$IgnoreCaseComparator

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.