* @return The display String
*/
public static String toHexString(ByteBuffer buffer, int offset, int size) {
-
- StringBuffer rtn = new StringBuffer();
+ return toHexString(buffer, offset, size, true);
+ }
+
+ /**
+ * Convert a byte buffer to a hexadecimal string for display
+ * @param buffer Buffer to display, starting at offset 0
+ * @param offset Offset at which to start reading the buffer
+ * @param size Number of bytes to read from the buffer
+ * @param formatted flag indicating if formatting is required
+ * @return The display String
+ */
+ public static String toHexString(ByteBuffer buffer,
+ int offset, int size, boolean formatted) {
+
+ StringBuilder rtn = new StringBuilder();
int position = buffer.position();
buffer.position(offset);
-
+
for (int i = 0; i < size; i++) {
byte b = buffer.get();
byte h = (byte) (b & 0xF0);
h = (byte) (h >>> 4);
- h = (byte) (h & 0x0F);
+ h = (byte) (h & 0x0F);
+ rtn.append(HEX_CHARS[(int) h]);
+ h = (byte) (b & 0x0F);
rtn.append(HEX_CHARS[(int) h]);
- h = (byte) (b & 0x0F);
- rtn.append(HEX_CHARS[(int) h] + " ");
- if ((i + 1) % 4 == 0) {
+
+ if (formatted == true)
+ {
rtn.append(" ");
- }
- if ((i + 1) % 24 == 0) {
- rtn.append("\n");
+
+ if ((i + 1) % 4 == 0) {
+ rtn.append(" ");
+ }
+ if ((i + 1) % 24 == 0) {
+ rtn.append("\n");
+ }
}
}
-
+
buffer.position(position);
return rtn.toString();
- }
+ }
+
}
intVal = intVal.negate();
}
return new BigDecimal(intVal, getScale());
+
+ } else if (_type == DataType.GUID) {
+
+ StringBuilder sb = new StringBuilder(22);
+ sb.append("{");
+ sb.append(ByteUtil.toHexString(buffer, 0, 4,
+ false));
+ sb.append("-");
+ sb.append(ByteUtil.toHexString(buffer, 4, 2,
+ false));
+ sb.append("-");
+ sb.append(ByteUtil.toHexString(buffer, 6, 2,
+ false));
+ sb.append("-");
+ sb.append(ByteUtil.toHexString(buffer, 8, 2,
+ false));
+ sb.append("-");
+ sb.append(ByteUtil.toHexString(buffer, 10, 6,
+ false));
+ sb.append("}");
+ return (sb.toString());
+
+ } else if (_type == DataType.UNKNOWN_0D) {
- } else if (_type == DataType.UNKNOWN_0D || _type == DataType.GUID) {
return null;
} else {
throw new IOException("Unrecognized data type: " + _type);
return _format.SIZE_LONG_VALUE_DEF;
} else if (_type == DataType.NUMERIC) {
return 17;
- } else if (_type == DataType.UNKNOWN_0D || _type == DataType.GUID) {
+ } else if (_type == DataType.GUID) {
+ return 16;
+ } else if (_type == DataType.UNKNOWN_0D) {
throw new IllegalArgumentException("FIX ME");
} else {
throw new IllegalArgumentException("Unrecognized data type: " + _type);
}
public String toString() {
- StringBuffer rtn = new StringBuffer();
+ StringBuilder rtn = new StringBuilder();
rtn.append("\tName: " + _name);
rtn.append("\n\tType: 0x" + Integer.toHexString((int)_type.getValue()));
rtn.append("\n\tNumber: " + _columnNumber);
OLE((byte) 0x0B, Types.LONGVARBINARY, 12),
MEMO((byte) 0x0C, Types.LONGVARCHAR, 12),
UNKNOWN_0D((byte) 0x0D),
- GUID((byte) 0x0F),
+ GUID((byte) 0x0F, null, 16),
NUMERIC((byte) 0x10, Types.NUMERIC, 17);
/** Map of SQL types to Access data types */
/** SQL type equivalent, or null if none defined */
private Integer _sqlType;
- DataType(byte value) {
+ private DataType(byte value) {
_value = value;
}
- DataType(byte value, int sqlType, int size) {
+ private DataType(byte value, Integer sqlType, Integer size) {
this(value);
_sqlType = sqlType;
_size = size;
}
- DataType(byte value, int sqlType, int size, boolean variableLength) {
+ private DataType(byte value, Integer sqlType, Integer size,
+ boolean variableLength) {
this(value, sqlType, size);
_variableLength = variableLength;
}
}
public String toString() {
- StringBuffer rtn = new StringBuffer();
+ StringBuilder rtn = new StringBuilder();
rtn.append("\tName: " + _name);
rtn.append("\n\tNumber: " + _indexNumber);
rtn.append("\n\tPage number: " + _pageNumber);
byte flag = buffer.get();
if (flag != (byte) 0) {
if (col.getType() == DataType.TEXT) {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
byte b;
while ( (b = buffer.get()) != (byte) 1) {
if ((int) b == 43) {
}
public String toString() {
- StringBuffer rtn = new StringBuffer();
+ StringBuilder rtn = new StringBuilder();
rtn.append("Type: " + _tableType);
rtn.append("\nRow count: " + _rowCount);
rtn.append("\nColumn count: " + _columnCount);
*/
public String display(long limit) throws IOException {
reset();
- StringBuffer rtn = new StringBuffer();
+ StringBuilder rtn = new StringBuilder();
Iterator iter = _columns.iterator();
while (iter.hasNext()) {
Column col = (Column) iter.next();