List of usage examples for io.netty.util CharsetUtil UTF_8
Charset UTF_8
To view the source code for io.netty.util CharsetUtil UTF_8.
Click Source Link
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 ww w . ja v a2s.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.MyLoadDataResponse.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeByte(0xFB); cb.writeBytes(fileName.getBytes(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();//w w w . j av a 2 s .co 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;/*w w w . java 2 s . co m*/ } 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.libmy.MyOKResponse.java
License:Open Source License
@Override public void unmarshallMessage(ByteBuf cb) { cb.readByte(); // field count - always 0 affectedRows = MysqlAPIUtils.getLengthCodedLong(cb); insertId = MysqlAPIUtils.getLengthCodedLong(cb); serverStatus = cb.readUnsignedShort(); warningCount = cb.readUnsignedShort(); if (cb.isReadable()) message = MysqlAPIUtils.readBytesAsString(cb, CharsetUtil.UTF_8); }
From source file:com.tesora.dve.db.mysql.portal.MSPAuthenticateHandlerV10.java
License:Open Source License
protected MyMessage doAuthenticate(ChannelHandlerContext ctx, MSPAuthenticateV10MessageMessage authMessage) throws Throwable { MyMessage mysqlResp;// w w w .j av a 2s.c om byte clientCharsetId = authMessage.getCharsetID(); String username = authMessage.getUsername(); String password = authMessage.getPassword(); SSConnection ssCon = ctx.channel().attr(ConnectionHandlerAdapter.SSCON_KEY).get(); ssCon.setClientCapabilities(authMessage.getClientCapabilities()); UserCredentials userCred = new UserCredentials(username, password, false); ssCon.startConnection(userCred); String initialDB = authMessage.getInitialDatabase(); if (!"".equals(authMessage.getInitialDatabase())) { final DBEmptyTextResultConsumer resultConsumer = new DBEmptyTextResultConsumer(); byte[] query = ("USE " + initialDB).getBytes(CharsetUtil.UTF_8); ExecuteRequestExecutor.execute(ssCon, resultConsumer, query); } NativeCharSet cliendCharSet = MysqlNativeCharSetCatalog.DEFAULT_CATALOG .findCharSetByCollationId(clientCharsetId); if (cliendCharSet != null) { mysqlResp = new MyOKResponse(); ssCon.setClientCharSet(cliendCharSet); } else { mysqlResp = new MyErrorResponse( new PEException("Unsupported character set specified (id=" + clientCharsetId + ")")); } return mysqlResp; }
From source file:com.tesora.dve.db.mysql.portal.MSPAuthenticateV10Message.java
License:Open Source License
@Override public void execute(ExecutorService clientExecutorService, ChannelHandlerContext ctx, SSConnection ssCon, MSPMessage protocolMessage) throws PEException { MSPAuthenticateV10MessageMessage authMessage = castProtocolMessage(MSPAuthenticateV10MessageMessage.class, protocolMessage);//from www . j a va2 s .com ssCon.setClientCapabilities(authMessage.getClientCapabilities()); byte clientCharsetId = authMessage.getCharsetID(); String username = authMessage.getUsername(); String password = authMessage.getPassword(); // Login in the SSConnection MyMessage mysqlResp; try { UserCredentials userCred = new UserCredentials(username, password, false); ssCon.startConnection(userCred); String initialDB = authMessage.getInitialDatabase(); if (!"".equals(authMessage.getInitialDatabase())) { final DBEmptyTextResultConsumer resultConsumer = new DBEmptyTextResultConsumer(); byte[] query = ("USE " + initialDB).getBytes(CharsetUtil.UTF_8); ExecuteRequestExecutor.execute(ssCon, resultConsumer, query); } NativeCharSet cliendCharSet = MysqlNativeCharSetCatalog.DEFAULT_CATALOG .findCharSetByCollationId(clientCharsetId); if (cliendCharSet != null) { mysqlResp = new MyOKResponse(); ssCon.setClientCharSet(cliendCharSet); } else { mysqlResp = new MyErrorResponse( new PEException("Unsupported character set specified (id=" + clientCharsetId + ")")); } } catch (PEException e) { mysqlResp = new MyErrorResponse(e.rootCause()); } catch (Throwable t) { mysqlResp = new MyErrorResponse(new Exception(t.getMessage())); } ctx.writeAndFlush(mysqlResp); }
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 {//from www . j ava 2 s. c o m parseValues.initialDatabase = ""; } return parseValues; }
From source file:com.tesora.dve.db.mysql.RedistTupleBuilder.java
License:Open Source License
public SQLCommand buildInsertStatement(int tupleCount) throws PEException { return QueryStepMultiTupleRedistOperation.getTableInsertStatement(/* * PerHostConnectionManager.INSTANCE.lookupConnection(targetWG * .getCommectionId()) */CharsetUtil.UTF_8, targetTable, insertOptions, rowSetMetadata, tupleCount, insertIgnore); }
From source file:com.tesora.dve.db.NativeResultHandler.java
License:Open Source License
public String getObjectAsString(ColumnMetadata uc, Object obj) throws PEException { String colStr;// w w w .ja v a2 s. co 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; }