Package java.nio.charset

Examples of java.nio.charset.CharsetDecoder


    }
   
    private static IRubyObject convert(ThreadContext context, String decodeCharset,
            String encodeCharset, IRubyObject str) {
        Ruby runtime = context.getRuntime();
        CharsetDecoder decoder;
        CharsetEncoder encoder;
        try {
            decoder = Charset.forName(decodeCharset).newDecoder();
            encoder = Charset.forName(encodeCharset).newEncoder();
        } catch (UnsupportedCharsetException e) {
            throw runtime.newArgumentError("invalid encoding");
        }
       
        ByteList bytes = str.convertToString().getByteList();
        ByteBuffer buf = ByteBuffer.wrap(bytes.unsafeBytes(), bytes.begin(), bytes.length());
        try {
            CharBuffer cbuf = decoder.decode(buf);
            buf = encoder.encode(cbuf);
        } catch (CharacterCodingException e) {
            throw runtime.newArgumentError("invalid encoding");
        }
        byte[] arr = buf.array();
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

        Assert.assertNotSame(nioBuf, ByteBuffer.allocate(16).buf());
    }

    public void testGetString() throws Exception {
        ByteBuffer buf = ByteBuffer.allocate(16);
        CharsetDecoder decoder;

        Charset charset = Charset.forName("UTF-8");
        buf.clear();
        buf.putString("hello", charset.newEncoder());
        buf.put((byte) 0);
View Full Code Here

    }

    public void testGetPrefixedString() throws Exception {
        ByteBuffer buf = ByteBuffer.allocate(16);
        CharsetEncoder encoder;
        CharsetDecoder decoder;
        encoder = Charset.forName("ISO-8859-1").newEncoder();
        decoder = Charset.forName("ISO-8859-1").newDecoder();

        buf.putShort((short) 3);
        buf.putString("ABCD", encoder);
View Full Code Here

                    if (ctx.getOverflowLength() == 0) {
                        ByteBuffer buf = ctx.getBuffer();
                        buf.flip();
                        buf.limit(buf.limit() - matchCount);

                        CharsetDecoder decoder = ctx.getDecoder();
                        CharBuffer buffer = decoder.decode(buf);
                        decoded = new String(buffer.array());
                    } else {
                        int overflowPosition = ctx.getOverflowLength();
                        throw new IllegalStateException("Line is too long: " + overflowPosition);
                    }
View Full Code Here

                        if (ctx.getOverflowLength() == 0) {
                            ByteBuffer buf = ctx.getBuffer();
                            buf.flip();
                            buf.limit(buf.limit() - matchCount);

                            CharsetDecoder decoder = ctx.getDecoder();
                            CharBuffer buffer = decoder.decode(buf);
                            decoded = new String(buffer.array());
                        } else {
                            int overflowLength = ctx.getOverflowLength();
                            throw new IllegalStateException("Line is too long: " + overflowLength);
                        }
View Full Code Here

    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    DependencyRevChecker revChecker = new DependencyRevChecker(ivyXmlFile);
    xmlReader.setContentHandler(revChecker);
    xmlReader.setErrorHandler(revChecker);
    // To work around a bug in XERCES (XERCESJ-1257), we assume the XML is always UTF8, so we simply provide reader.
    CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder()
        .onMalformedInput(CodingErrorAction.REPORT)
        .onUnmappableCharacter(CodingErrorAction.REPORT);
    InputStream stream = new FileInputStream(ivyXmlFile);
    xmlReader.parse(new InputSource(new BufferedReader(new InputStreamReader(stream, decoder))));
    return ! revChecker.fail;
View Full Code Here

  }
 
  public static ConnectionCostsWriter build(String filename) throws IOException {
    FileInputStream inputStream = new FileInputStream(filename);
    Charset cs = Charset.forName("US-ASCII");
    CharsetDecoder decoder = cs.newDecoder()
        .onMalformedInput(CodingErrorAction.REPORT)
        .onUnmappableCharacter(CodingErrorAction.REPORT);
    InputStreamReader streamReader = new InputStreamReader(inputStream, decoder);
    LineNumberReader lineReader = new LineNumberReader(streamReader);
   
View Full Code Here

      throws IOException {
    UnknownDictionaryWriter dictionary = new UnknownDictionaryWriter(5 * 1024 * 1024);
   
    FileInputStream inputStream = new FileInputStream(filename);
    Charset cs = Charset.forName(encoding);
    CharsetDecoder decoder = cs.newDecoder()
        .onMalformedInput(CodingErrorAction.REPORT)
        .onUnmappableCharacter(CodingErrorAction.REPORT);
    InputStreamReader streamReader = new InputStreamReader(inputStream, decoder);
    LineNumberReader lineReader = new LineNumberReader(streamReader);
   
View Full Code Here

    System.out.println("  parse...");
    List<String[]> lines = new ArrayList<String[]>(400000);
    for (File file : csvFiles){
      FileInputStream inputStream = new FileInputStream(file);
      Charset cs = Charset.forName(encoding);
      CharsetDecoder decoder = cs.newDecoder()
          .onMalformedInput(CodingErrorAction.REPORT)
          .onUnmappableCharacter(CodingErrorAction.REPORT);
      InputStreamReader streamReader = new InputStreamReader(inputStream, decoder);
      BufferedReader reader = new BufferedReader(streamReader);
     
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.