Package java.nio.charset

Examples of java.nio.charset.Charset


  public IValue readFile(ISourceLocation sloc, IEvaluatorContext ctx){
    sloc = ctx.getHeap().resolveSourceLocation(sloc);
    Reader reader = null;
   
    try {
      Charset c = ctx.getResolverRegistry().getCharset(sloc.getURI());
      if (c != null) {
        return readFileEnc(sloc, values.string(c.name()), ctx);
      }
      sloc = ctx.getHeap().resolveSourceLocation(sloc);
      reader = ctx.getResolverRegistry().getCharacterReader(sloc.getURI());
      return consumeInputStream(sloc, reader, ctx);
    } 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 = ctx.getResolverRegistry().getCharset(sloc.getURI());
        if (detected == null) {
          in = ctx.getResolverRegistry().getInputStream(sloc.getURI());
          detected = UnicodeDetector.estimateCharset(in);
        }
      }catch(FileNotFoundException fnfex){
        throw RuntimeExceptionFactory.pathNotFound(sloc, ctx.getCurrentAST(), null);
      } catch (IOException e) {
        throw RuntimeExceptionFactory.io(values.string(e.getMessage()), ctx.getCurrentAST(), null);
      }
      finally {
        if (in != null) {
          try {
            in.close();
          } catch (IOException e) {
            throw RuntimeExceptionFactory.io(values.string(e.getMessage()), ctx.getCurrentAST(), null);
          }
        }
      }
      if (detected != null)
        charset = values.string(detected.name());
      else {
        charset = values.string(Charset.defaultCharset().name());
      }
    }
    writeFileEnc(sloc, charset, V, append, ctx);
View Full Code Here

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

        cb = openBuffer(f);
    }

    private CharBuffer openBuffer(IFile f) throws IOException, CoreException
    {
        Charset charset = Charset.forName(f.getCharset());
        CharsetDecoder decoder = charset.newDecoder();
        // Open the file and then get a channel from the stream
        FileInputStream fis = new FileInputStream(f.getLocation().toFile());
        fc = fis.getChannel();

        // Get the file's size and then map it into memory
View Full Code Here

    private void writeHeader() throws IOException {
     
      out = new FileOutputStream(outputFile);
         
      // write header 
      Charset charSet = Charset.forName("US-ASCII");
      out.write("P6\n".getBytes(charSet));
      out.write(String.format("%d %d\n", cols, rows).getBytes(charSet));
      out.write("255\n".getBytes(charSet));

      fc = out.getChannel();     
View Full Code Here

        if(MavenProcessFactory.debug)
            listener.getLogger().println("Using env variables: "+ envVars);
        try {
            //launcher.getChannel().export( type, instance )
            final Acceptor acceptor = launcher.getChannel().call(new SocketHandler());
            Charset charset;
            try {
                charset = Charset.forName(launcher.getChannel().call(new GetCharset()));
            } catch (UnsupportedCharsetException e) {
                // choose the bit preserving charset. not entirely sure if iso-8859-1 does that though.
                charset = Charset.forName("iso-8859-1");
View Full Code Here

    // warm up
    baos.write(ba);
    baos.write(ba);
    baos.write(ba);
    baos.write(ba);
    Charset UTF8 = Charset.forName("UTF-8");
    for (int i = 0; i < 1000; i++) {
      {
        baos.reset();
        long t0 = System.nanoTime();
        baos.write(ba);
View Full Code Here

  }

  @Test
  public void strings() {
    String ss = "仰望着天空寻找一位失去的故友悄无声息的离开了也带上了命运";
    Charset UTF8 = Charset.forName("UTF-8");
    CharsetEncoder enc = UTF8.newEncoder();
    // enc.

  }
View Full Code Here

            catch(IOException e) {
                LOGGER.log(Level.FINE, contentEncoding + " read failed; try plain reading", e);;                       
            }
            // extract charset from content-type header
            // e.g. Content-Type: text/html; charset=ISO-8859-4
            Charset charSet = Charset.defaultCharset();
            int charSetIdx;
            if ((contentType != null) && ((charSetIdx = contentType.indexOf(CHARSET_KEY)) > 0)) {
                charSetIdx += CHARSET_KEY.length(); // skip
                final int nextSemicolon = contentType.indexOf(';', charSetIdx);
                final int endIndex = nextSemicolon < 0 ? contentType.length() : nextSemicolon;                             
View Full Code Here

     */

    private HttpResponse uploadMultiPart(String path,
            Map<String, String> reqParams, InputStream ins, String fileName)
            throws Exception {
        Charset utf8 = Charset.availableCharsets().get("UTF-8");
        MultipartEntity reqEntity = new MultipartEntity();
        HttpPost httppost = new HttpPost(getRequestBuilder().buildUrl(path));
        if (reqParams != null) {
            for (Map.Entry<String, String> entry : reqParams.entrySet()) {
                String key = entry.getKey();
View Full Code Here

TOP

Related Classes of java.nio.charset.Charset

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.