use of java.nio.charset.CharacterCodingException in project cassandra by apache.
the class CBUtil method readString.
private static String readString(ByteBuf cb, int length) {
if (length == 0)
return "";
ByteBuffer buffer = cb.nioBuffer(cb.readerIndex(), length);
try {
String str = decodeString(buffer);
cb.readerIndex(cb.readerIndex() + length);
return str;
} catch (IllegalStateException | CharacterCodingException e) {
throw new ProtocolException("Cannot decode string as UTF8: '" + ByteBufferUtil.bytesToHex(buffer) + "'; " + e);
}
}
use of java.nio.charset.CharacterCodingException in project cassandra by apache.
the class SettingsSchema method createCounter1StatementCQL3.
String createCounter1StatementCQL3(StressSettings settings) {
StringBuilder b = new StringBuilder();
b.append("CREATE TABLE IF NOT EXISTS ").append("counter1 (key blob PRIMARY KEY,");
try {
for (ByteBuffer name : settings.columns.names) b.append("\n, \"").append(ByteBufferUtil.string(name)).append("\" counter");
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
//Compression
b.append(") WITH COMPACT STORAGE AND compression = {");
if (compression != null)
b.append("'sstable_compression' : '").append(compression).append("'");
b.append("}");
//Compaction
if (compactionStrategy != null) {
b.append(" AND compaction = { 'class' : '").append(compactionStrategy).append("'");
for (Map.Entry<String, String> entry : compactionStrategyOptions.entrySet()) b.append(", '").append(entry.getKey()).append("' : '").append(entry.getValue()).append("'");
b.append("}");
}
b.append(";\n");
return b.toString();
}
use of java.nio.charset.CharacterCodingException in project japid42 by branaway.
the class StringUtils method encodeUTF8.
/**
* try to encode a char[] as fast as possible for later use in outputstream
*
* @param ca
* @param off
* @param len
* @return
*/
public static ByteBuffer encodeUTF8(String src) {
// char[] ca = src.toCharArray();
int len = src.length();
int off = 0;
int en = (int) (len * ce.maxBytesPerChar());
byte[] ba = new byte[en];
if (len == 0)
return null;
ce.reset();
ByteBuffer bb = ByteBuffer.wrap(ba);
CharBuffer cb = CharBuffer.wrap(src, off, len);
try {
CoderResult cr = ce.encode(cb, bb, true);
if (!cr.isUnderflow())
cr.throwException();
cr = ce.flush(bb);
if (!cr.isUnderflow())
cr.throwException();
return bb;
} catch (CharacterCodingException x) {
// so this shouldn't happen
throw new Error(x);
}
}
use of java.nio.charset.CharacterCodingException in project hive by apache.
the class LazyHiveVarchar method init.
@Override
public void init(ByteArrayRef bytes, int start, int length) {
if (oi.isEscaped()) {
Text textData = data.getTextValue();
// This is doing a lot of copying here, this could be improved by enforcing length
// at the same time as escaping rather than as separate steps.
LazyUtils.copyAndEscapeStringDataToText(bytes.getData(), start, length, oi.getEscapeChar(), textData);
data.set(textData.toString(), maxLength);
isNull = false;
} else {
try {
String byteData = null;
byteData = Text.decode(bytes.getData(), start, length);
data.set(byteData, maxLength);
isNull = false;
} catch (CharacterCodingException e) {
isNull = true;
LOG.debug("Data not in the HiveVarchar data type range so converted to null.", e);
}
}
}
use of java.nio.charset.CharacterCodingException in project hive by apache.
the class LazyPrimitive method logExceptionMessage.
public void logExceptionMessage(ByteArrayRef bytes, int start, int length, String dataType) {
try {
if (LOG.isDebugEnabled()) {
String byteData = Text.decode(bytes.getData(), start, length);
LOG.debug("Data not in the " + dataType + " data type range so converted to null. Given data is :" + byteData, new Exception("For debugging purposes"));
}
} catch (CharacterCodingException e1) {
LOG.debug("Data not in the " + dataType + " data type range so converted to null.", e1);
}
}
Aggregations