axml/src/main/java/fr/xgouchet/axml/AXMLParser.java
private String readString(final int offset,
                              final int encoding,
                              final String charsetName)
            throws UnsupportedEncodingException {

        int bytesCount, charOffset, charsCount;
        byte data[];
        String result;

        // Each string is prefix by 2 bytes indicating the length of the string
        charOffset = offset + 2;

        switch (encoding) {
            case ENCODING_UTF8:
                charsCount = mBuffer[offset];
                bytesCount = mBuffer[offset + 1];
                data = new byte[bytesCount];
                break;
            case ENCODING_UTF16_LE:
                charsCount = ((mBuffer[offset + 1] << 8) & 0xFF00) | (mBuffer[offset] & 0xFF);
                bytesCount = charsCount * 2;
                data = new byte[bytesCount];
                break;
            default:
                throw new UnsupportedEncodingException();
        }

        // copy the string bytes
        System.arraycopy(mBuffer, charOffset, data, 0, bytesCount);

        // Convert to string
        try {
            result = new String(data, charsetName);
            if (result.length() != charsCount) {
                logError("Decoding seems off, expecting " + charsCount + " characters, final String has " + result.length());
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            result = "";
        }
        return result;
    }
/**
     * @param offset offset of the beginning of the string inside the StringTable (and not the whole
     *               data array)
     * @return the String
     */
@param offset offset of the beginning of the string inside the StringTable (and not the whole
data array)
@return the String
@param offset offset of the beginning of the string inside the StringTable ( and not the whole data array ) @return the String
private String readString(final int offset,
                              final int encoding,
                              final String charsetName)
            throws UnsupportedEncodingException {
        int bytesCount, charOffset, charsCount;
        byte data[];
        String result;
        charOffset = offset + 2;
        switch (encoding) {
            case ENCODING_UTF8:
                charsCount = mBuffer[offset];
                bytesCount = mBuffer[offset + 1];
                data = new byte[bytesCount];
                break;
            case ENCODING_UTF16_LE:
                charsCount = ((mBuffer[offset + 1] << 8) & 0xFF00) | (mBuffer[offset] & 0xFF);
                bytesCount = charsCount * 2;
                data = new byte[bytesCount];
                break;
            default:
                throw new UnsupportedEncodingException();
        }
        System.arraycopy(mBuffer, charOffset, data, 0, bytesCount);
        try {
            result = new String(data, charsetName);
            if (result.length() != charsCount) {
                logError("Decoding seems off, expecting " + charsCount + " characters, final String has " + result.length());
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            result = "";
        }
        return result;
    }
private String readString ( final int offset , final int encoding , final String charsetName ) throws UnsupportedEncodingException { int bytesCount , charOffset , charsCount ; byte data [ ] ; String result ; charOffset = offset + 2 ; switch ( encoding ) { case ENCODING_UTF8 : charsCount = mBuffer [ offset ] ; bytesCount = mBuffer [ offset + 1 ] ; data = new byte [ bytesCount ] ; break ; case ENCODING_UTF16_LE : charsCount = ( ( mBuffer [ offset + 1 ] << 8 ) & 0xFF00 ) | ( mBuffer [ offset ] & 0xFF ) ; bytesCount = charsCount * 2 ; data = new byte [ bytesCount ] ; break ; default : throw new UnsupportedEncodingException ( ) ; } System . arraycopy ( mBuffer , charOffset , data , 0 , bytesCount ) ; try { result = new String ( data , charsetName ) ; if ( result . length ( ) != charsCount ) { logError ( "Decoding seems off, expecting " + charsCount + " characters, final String has " + result . length ( ) ) ; } } catch ( UnsupportedEncodingException e ) { e . printStackTrace ( ) ; result = "" ; } return result ; }
@param offset offset of the beginning of the string inside the StringTable (and not the whole
               data array)
 @return the String
@param offset offset of the beginning of the string inside the StringTable ( and not the whole data array ) @return the String
// Each string is prefix by 2 bytes indicating the length of the string // copy the string bytes // Convert to string