Example usage for io.netty.util CharsetUtil ISO_8859_1

List of usage examples for io.netty.util CharsetUtil ISO_8859_1

Introduction

In this page you can find the example usage for io.netty.util CharsetUtil ISO_8859_1.

Prototype

Charset ISO_8859_1

To view the source code for io.netty.util CharsetUtil ISO_8859_1.

Click Source Link

Document

ISO Latin Alphabet No.

Usage

From source file:com.tesora.dve.comms.client.messages.ConnectRequest.java

License:Open Source License

public Charset getCharset() {
    // if the Charset wasn't provided, default to ISO_8859_1
    if (charset != null)
        return Charset.forName(charset);

    return CharsetUtil.ISO_8859_1;
}

From source file:com.tesora.dve.db.mysql.DBTypeBasedUtilsTest.java

License:Open Source License

@Test
public void mysqlConvertToObjectTest() throws Exception {
    ColumnMetadata colMd = new ColumnMetadata();
    FastDateFormat fdfDate = FastDateFormat.getInstance(MysqlNativeConstants.MYSQL_DATE_FORMAT);
    FastDateFormat fdfDateTime = FastDateFormat.getInstance(MysqlNativeConstants.MYSQL_DATETIME_FORMAT);
    FastDateFormat fdfTime = FastDateFormat.getInstance(MysqlNativeConstants.MYSQL_TIME_FORMAT);
    FastDateFormat fdfTimestamp = FastDateFormat.getInstance(MysqlNativeConstants.MYSQL_TIMESTAMP_FORMAT);

    for (Pair<MyFieldType, Object> expValue : expValuesMysql) {
        DataTypeValueFunc dtvf = DBTypeBasedUtils.getMysqlTypeFunc(expValue.getFirst());
        assertNotNull("Couldn't find function for " + expValue.getFirst(), dtvf);
        if (expValue.getSecond() != null) {
            String value;/*from  w ww . java  2s  .c  o m*/
            if (MyFieldType.FIELD_TYPE_DATE.equals(expValue.getFirst())) {
                value = fdfDate.format(expValue.getSecond());
            } else if (MyFieldType.FIELD_TYPE_DATETIME.equals(expValue.getFirst())) {
                value = fdfDateTime.format(expValue.getSecond());
            } else if (MyFieldType.FIELD_TYPE_TIME.equals(expValue.getFirst())) {
                value = fdfTime.format(expValue.getSecond());
            } else if (MyFieldType.FIELD_TYPE_TIMESTAMP.equals(expValue.getFirst())) {
                value = fdfTimestamp.format(expValue.getSecond());
            } else if (MyFieldType.FIELD_TYPE_BIT.equals(expValue.getFirst())) {
                value = new String((byte[]) expValue.getSecond(), CharsetUtil.ISO_8859_1);
            } else {
                value = expValue.getSecond().toString();
            }

            Object valueObj = dtvf.convertStringToObject(value, colMd);
            assertEqualData(expValue.getSecond(), valueObj);
        }
    }
}

From source file:com.tesora.dve.db.mysql.libmy.MyHandshakeV10.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    protocolVersion = cb.readByte();/*from w  w w.  j ava2 s. co  m*/
    serverVersion = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8);
    cb.skipBytes(1); // skip the NULL terminator
    threadID = cb.readInt();
    scrambleBuffer1st = MysqlAPIUtils.readBytesAsString(cb, 8, CharsetUtil.ISO_8859_1);
    cb.skipBytes(1);
    long sc1 = cb.readUnsignedShort();
    serverCharset = cb.readByte();
    serverStatus = cb.readShort();
    long sc2 = Long.rotateLeft(cb.readUnsignedShort(), 16);
    setServerCapabilities(sc1 + sc2);
    scrambleBufferSize = new Integer(cb.readByte());
    cb.skipBytes(10); //unused bytes
    scrambleBuffer2nd = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.ISO_8859_1);
    cb.skipBytes(1);
    if ((serverCapabilitiesasLong
            & ClientCapabilities.CLIENT_PLUGIN_AUTH) == ClientCapabilities.CLIENT_PLUGIN_AUTH) {
        plugInProvidedData = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8);
    }
}

From source file:com.tesora.dve.db.mysql.libmy.MyLoginRequest.java

License:Open Source License

@Override
public void unmarshallMessage(ByteBuf cb) {
    clientCapabilities = cb.readUnsignedInt();
    boolean hasConnectDatabase = ((clientCapabilities
            & ClientCapabilities.CLIENT_CONNECT_WITH_DB) == ClientCapabilities.CLIENT_CONNECT_WITH_DB);
    maxPacketSize = cb.readInt();/*from   w w w. ja v a2s.c o  m*/
    clientCharset = cb.readByte();

    cb.skipBytes(23); // login request has a 23 byte filler
    username = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8);
    cb.skipBytes(1); // skip the NULL terminator
    byte passwordLength = cb.readByte();
    byte[] passwordBytes = new byte[passwordLength];
    cb.getBytes(cb.readerIndex(), passwordBytes, 0, passwordLength);
    password = new String(passwordBytes, CharsetUtil.ISO_8859_1);
    cb.skipBytes(passwordLength);
    // if the clientCapabilities flag has the CLIENT_CONNECT_WITH_DB bit set,
    // then this message contains an initial database to connect to
    if (hasConnectDatabase) {
        database = cb.readSlice(cb.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8);
        if (database.length() < 1) {
            database = null;
        }
    }
}

From source file:com.tesora.dve.db.mysql.libmy.MyLoginRequest.java

License:Open Source License

@Override
public void marshallMessage(ByteBuf cb) {
    boolean hasConnectDatabase = false;
    if (database != null) {
        clientCapabilities = clientCapabilities + ClientCapabilities.CLIENT_CONNECT_WITH_DB;
        hasConnectDatabase = true;/* ww  w.  j  av  a2  s  .c om*/
    }
    cb.writeInt((int) clientCapabilities);
    cb.writeInt(maxPacketSize);
    cb.writeByte(clientCharset);
    cb.writeZero(23); // filler
    cb.writeBytes(username.getBytes(CharsetUtil.UTF_8));
    cb.writeZero(1); // null terminator for username
    byte[] passwordBytes = password.getBytes(CharsetUtil.ISO_8859_1);
    MysqlAPIUtils.putLengthCodedString(cb, passwordBytes, false);
    if (hasConnectDatabase) {
        cb.writeBytes(database.getBytes(CharsetUtil.UTF_8));
        cb.writeZero(1); // null terminator for database
    }
    if (plugInData != null) {
        cb.writeBytes(plugInData.getBytes(CharsetUtil.UTF_8));
        cb.writeZero(1); // null terminator for plugInData
    }
}

From source file:com.tesora.dve.db.mysql.portal.protocol.MSPAuthenticateV10MessageMessage.java

License:Open Source License

@Override
protected ParsedData unmarshall(ByteBuf source) {
    ParsedData parseValues = new ParsedData();
    parseValues.caps = new ClientCapabilities(source.readUnsignedInt());
    parseValues.maxPacketSize = source.readInt();
    parseValues.charsetID = source.readByte();

    source.skipBytes(23); // login request has a 23 byte filler
    parseValues.username = source.readSlice(source.bytesBefore((byte) 0)).toString(CharsetUtil.UTF_8);
    source.skipBytes(1); // skip the NULL terminator
    byte passwordLength = source.readByte();
    parseValues.password = source.readSlice(passwordLength).toString(CharsetUtil.ISO_8859_1);

    // if the clientCapabilities flag has the CLIENT_CONNECT_WITH_DB bit set,
    // then this message contains an initial database to connect to
    if (parseValues.caps.connectWithDB()) {
        parseValues.initialDatabase = source.readSlice(source.bytesBefore((byte) 0))
                .toString(CharsetUtil.UTF_8);
        source.skipBytes(1); // skip the NULL terminator
    } else {/*w  w w . ja v  a 2 s  .co  m*/
        parseValues.initialDatabase = "";
    }
    return parseValues;
}

From source file:com.tesora.dve.db.mysql.portal.protocol.MSPAuthenticateV10MessageMessage.java

License:Open Source License

public static String computeSecurePasswordString(String password, String salt) {
    return new String(computeSecurePassword(password, salt), CharsetUtil.ISO_8859_1);
}

From source file:com.tesora.dve.db.NativeResultHandler.java

License:Open Source License

public String getObjectAsString(ColumnMetadata uc, Object obj) throws PEException {
    String colStr;//  ww  w . j a  v  a  2 s . c  o  m
    byte[] b = getObjectAsBytes(uc, obj);
    //      try {
    if (uc.getDataType() == Types.BLOB || uc.getDataType() == Types.LONGVARBINARY) {
        colStr = new String(b, CharsetUtil.ISO_8859_1);
    } else {
        colStr = new String(b, CharsetUtil.UTF_8);
    }
    //      } catch (UnsupportedEncodingException e) {
    //         // Just return the default encoding
    //         colStr = new String(b);
    //      }
    return colStr;
}

From source file:com.tesora.dve.db.ValueConverter.java

License:Open Source License

public byte[] convertBinaryLiteral(Object in) {
    if (in instanceof String) {
        return ((String) in).getBytes(CharsetUtil.ISO_8859_1);
    }/* w  w w.j  a v  a2 s  .co  m*/
    throw new ConversionException(Pass.PLANNER,
            "Unknown object type for convertBinaryLiteral: " + in.getClass().getName());
}

From source file:com.tesora.dve.server.connectionmanager.loaddata.LoadDataRequestExecutor.java

License:Open Source License

static void createPreparedStatement(SSConnection connMgr, ChannelHandlerContext ctx, Charset charSet,
        MysqlLoadDataInfileRequestCollector resultConsumer, String insertPrefix, String parameterizedTuple,
        int numColumns, int numTuples) throws PEException {

    StringBuilder insert = new StringBuilder(insertPrefix);
    boolean first = true;
    for (int i = 0; i < numTuples; i++) {
        if (!first) {
            insert.append(",");
        }/*  w w w .  j  a  v a2 s .  c  o  m*/
        insert.append(parameterizedTuple);
        first = false;
    }

    MyPreparedStatement<String> pStmt = new MyPreparedStatement<String>(null);
    pStmt.setQuery(insert.toString().getBytes(CharsetUtil.ISO_8859_1));
    pStmt.setNumColumns(numColumns);
    pStmt.setNumParams(numColumns);

    resultConsumer.getLoadDataInfileContext().addPreparedStatement(numTuples, pStmt);
    resultConsumer.getLoadDataInfileContext().getOrCreatePrepStmtContextFromChannel(connMgr, ctx)
            .addPreparedStatement(pStmt);

    MysqlPrepareStatementDiscarder prepStmtConsumer = new MysqlPrepareStatementDiscarder();
    try {
        PrepareRequestExecutor.execute(connMgr, prepStmtConsumer, pStmt.getStmtId(), charSet,
                insert.toString().getBytes(CharsetUtil.ISO_8859_1));
    } catch (Throwable t) {
        throw new PEException("Failed to prepare statement:" + insert.toString(), t);
    }
}