本文整理了Java中io.airlift.slice.Slice.toString()
方法的一些代码示例,展示了Slice.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Slice.toString()
方法的具体详情如下:
包路径:io.airlift.slice.Slice
类名称:Slice
方法名:toString
[英]Decodes the a portion of this slice into a string with the specified character set name.
[中]将该片段的一部分解码为具有指定字符集名称的字符串。
代码示例来源:origin: prestodb/presto
@UsedByGeneratedCode
public static long varcharToShortDecimal(Slice value, long precision, long scale, long tenToScale)
{
BigDecimal result;
String stringValue = value.toString(UTF_8);
try {
result = new BigDecimal(stringValue).setScale(intScale(scale), HALF_UP);
}
catch (NumberFormatException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value is not a number.", stringValue, precision, scale));
}
if (overflows(result, precision)) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value too large.", stringValue, precision, scale));
}
return result.unscaledValue().longValue();
}
代码示例来源:origin: prestodb/presto
@UsedByGeneratedCode
public static Slice varcharToLongDecimal(Slice value, long precision, long scale, BigInteger tenToScale)
{
BigDecimal result;
String stringValue = value.toString(UTF_8);
try {
result = new BigDecimal(stringValue).setScale(intScale(scale), HALF_UP);
}
catch (NumberFormatException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value is not a number.", stringValue, precision, scale));
}
if (overflows(result, precision)) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value too large.", stringValue, precision, scale));
}
return encodeUnscaledValue(result.unscaledValue());
}
代码示例来源:origin: confluentinc/ksql
protected Node visitBinaryLiteral(final BinaryLiteral node, final Object context) {
// May need some changes.
// use an if/else block here (instead of isPresent.map(...).orElse(...)) so only one object
// gets instantiated (issue #1784)
if (node.getLocation().isPresent()) {
return new BinaryLiteral(node.getLocation().get(), node.getValue().toString());
} else {
return new BinaryLiteral(node.getValue().toString());
}
}
代码示例来源:origin: airlift/slice
@Override
public String toString(Charset charset)
{
return slice.toString(0, size, charset);
}
}
代码示例来源:origin: io.airlift/slice
@Override
public String toString(Charset charset)
{
return slice.toString(0, size, charset);
}
}
代码示例来源:origin: io.airlift/slice
/**
* Decodes the contents of this slice into a string using the UTF-8
* character set.
*/
public String toStringUtf8()
{
return toString(UTF_8);
}
代码示例来源:origin: io.airlift/slice
@Override
public String toString(Charset charset)
{
return slice.toString(0, size, charset);
}
}
代码示例来源:origin: airlift/slice
/**
* Decodes the contents of this slice into a string using the UTF-8
* character set.
*/
public String toStringUtf8()
{
return toString(UTF_8);
}
代码示例来源:origin: airlift/slice
@Override
public String toString(Charset charset)
{
return slice.toString(0, size, charset);
}
}
代码示例来源:origin: stackoverflow.com
@Override
public String toString(){
for (Slice s:slices){
s.toString();
}
}
代码示例来源:origin: airlift/slice
/**
* Decodes the contents of this slice into a string with the specified
* character set name.
*/
public String toString(Charset charset)
{
return toString(0, length(), charset);
}
代码示例来源:origin: io.airlift/slice
/**
* Decodes the contents of this slice into a string with the specified
* character set name.
*/
public String toString(Charset charset)
{
return toString(0, length(), charset);
}
代码示例来源:origin: io.airlift/slice
/**
* Decodes this buffer's readable bytes into a string with the specified
* character set name. This method is identical to
* {@code buf.toString(buf.position(), buf.available()(), charsetName)}.
* This method does not modify {@code position} or {@code writerIndex} of
* this buffer.
*/
public String toString(Charset charset)
{
return slice.toString(position, available(), charset);
}
代码示例来源:origin: airlift/slice
/**
* Decodes this buffer's readable bytes into a string with the specified
* character set name. This method is identical to
* {@code buf.toString(buf.position(), buf.available()(), charsetName)}.
* This method does not modify {@code position} or {@code writerIndex} of
* this buffer.
*/
public String toString(Charset charset)
{
return slice.toString(position, available(), charset);
}
代码示例来源:origin: io.prestosql/presto-main
@UsedByGeneratedCode
public static long varcharToShortDecimal(Slice value, long precision, long scale, long tenToScale)
{
BigDecimal result;
String stringValue = value.toString(UTF_8);
try {
result = new BigDecimal(stringValue).setScale(intScale(scale), HALF_UP);
}
catch (NumberFormatException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value is not a number.", stringValue, precision, scale));
}
if (overflows(result, precision)) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value too large.", stringValue, precision, scale));
}
return result.unscaledValue().longValue();
}
代码示例来源:origin: prestosql/presto
@UsedByGeneratedCode
public static Slice varcharToLongDecimal(Slice value, long precision, long scale, BigInteger tenToScale)
{
BigDecimal result;
String stringValue = value.toString(UTF_8);
try {
result = new BigDecimal(stringValue).setScale(intScale(scale), HALF_UP);
}
catch (NumberFormatException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value is not a number.", stringValue, precision, scale));
}
if (overflows(result, precision)) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value too large.", stringValue, precision, scale));
}
return encodeUnscaledValue(result.unscaledValue());
}
代码示例来源:origin: io.prestosql/presto-main
@UsedByGeneratedCode
public static Slice varcharToLongDecimal(Slice value, long precision, long scale, BigInteger tenToScale)
{
BigDecimal result;
String stringValue = value.toString(UTF_8);
try {
result = new BigDecimal(stringValue).setScale(intScale(scale), HALF_UP);
}
catch (NumberFormatException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value is not a number.", stringValue, precision, scale));
}
if (overflows(result, precision)) {
throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast VARCHAR '%s' to DECIMAL(%s, %s). Value too large.", stringValue, precision, scale));
}
return encodeUnscaledValue(result.unscaledValue());
}
代码示例来源:origin: airlift/slice
@Test
public void testToString()
{
assertEquals(Slices.copiedBuffer("apple", UTF_8).toString(UTF_8), "apple");
for (int size = 0; size < 100; size++) {
for (int index = 0; index < size; index++) {
assertToStrings(allocate(size), index);
}
}
}
代码示例来源:origin: io.airlift/slice
@Test
public void testToString()
{
assertEquals(Slices.copiedBuffer("apple", UTF_8).toString(UTF_8), "apple");
for (int size = 0; size < 100; size++) {
for (int index = 0; index < size; index++) {
assertToStrings(allocate(size), index);
}
}
}
代码示例来源:origin: prestosql/presto
private static long parseMillis(TimeZoneKey timeZoneKey, Locale locale, Slice dateTime, Slice formatString)
{
DateTimeFormatter formatter = DATETIME_FORMATTER_CACHE.get(formatString)
.withChronology(CHRONOLOGIES[timeZoneKey.getKey()])
.withLocale(locale);
try {
return formatter.parseMillis(dateTime.toString(UTF_8));
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!