Java ByteBuffer Get getCPCharacter(ByteBuffer buffer)

Here you can find the source of getCPCharacter(ByteBuffer buffer)

Description

get CP Character

License

BEER-WARE LICENSE

Declaration

public static char getCPCharacter(ByteBuffer buffer) 

Method Source Code


//package com.java2s;
//License from project: BEER-WARE LICENSE 

import java.nio.ByteBuffer;

public class Main {
    private static final char[] CHARACTERS = { '\u20ac', '\0', '\u201a', '\u0192', '\u201e', '\u2026', '\u2020',
            '\u2021', '\u02c6', '\u2030', '\u0160', '\u2039', '\u0152', '\0', '\u017d', '\0', '\0', '\u2018',
            '\u2019', '\u201c', '\u201d', '\u2022', '\u2013', '\u2014', '\u02dc', '\u2122', '\u0161', '\u203a',
            '\u0153', '\0', '\u017e', '\u0178' };

    public static char getCPCharacter(ByteBuffer buffer) {
        int read = buffer.get() & 0xff;
        if (read == 0) {
            throw new IllegalArgumentException(
                    "Non cp1252 character 0x" + Integer.toString(read, 16) + " provided");
        }//from w ww. j a  va  2 s  .c om
        if (read >= 128 && read < 160) {
            char cpChar = CHARACTERS[read - 128];
            if (cpChar == '\0') {
                cpChar = '?';
            }
            read = cpChar;
        }
        return (char) read;
    }
}

Related

  1. getByte(ByteBuffer bb)
  2. getByte(ByteBuffer byteBuffer)
  3. getByteAsShort(java.nio.ByteBuffer buffer)
  4. getByteLen(ByteBuffer buffer)
  5. getChars(ByteBuffer buf, int off, int count)
  6. getCrcChecksum(ByteBuffer buffer)
  7. getCRLFCRLFIndex(ByteBuffer buffer)
  8. getCRLFIndex(ByteBuffer buffer)
  9. getCRLFLine(ByteBuffer buf)