本文整理汇总了Java中org.apache.qpid.proton.amqp.Binary.getArrayOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Binary.getArrayOffset方法的具体用法?Java Binary.getArrayOffset怎么用?Java Binary.getArrayOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.qpid.proton.amqp.Binary
的用法示例。
在下文中一共展示了Binary.getArrayOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toQuotedString
import org.apache.qpid.proton.amqp.Binary; //导入方法依赖的package包/类
/**
* Converts the Binary to a quoted string.
*
* @param bin the Binary to convert
* @param stringLength the maximum length of stringified content (excluding the quotes, and truncated indicator)
* @param appendIfTruncated appends "...(truncated)" if not all of the payload is present in the string
* @return the converted string
*/
public static String toQuotedString(final Binary bin,final int stringLength,final boolean appendIfTruncated)
{
if(bin == null)
{
return "\"\"";
}
final byte[] binData = bin.getArray();
final int binLength = bin.getLength();
final int offset = bin.getArrayOffset();
StringBuilder str = new StringBuilder();
str.append("\"");
int size = 0;
boolean truncated = false;
for (int i = 0; i < binLength; i++)
{
byte c = binData[offset + i];
if (c > 31 && c < 127 && c != '\\')
{
if (size + 1 <= stringLength)
{
size += 1;
str.append((char) c);
}
else
{
truncated = true;
break;
}
}
else
{
if (size + 4 <= stringLength)
{
size += 4;
str.append(String.format("\\x%02x", c));
}
else
{
truncated = true;
break;
}
}
}
str.append("\"");
if (truncated && appendIfTruncated)
{
str.append("...(truncated)");
}
return str.toString();
}