/** * Convert class of object to the correct ComponentType. * @param obj Input object (key component). * @return ComponentType representing the class of the input object. */ private static ComponentType getType(Object obj) { if (obj instanceof String) { return ComponentType.STRING; } else if (obj instanceof Integer) { return ComponentType.INTEGER; } else if (obj instanceof Long) { return ComponentType.LONG; } throw new EntityIdException("Unexpected type for Component " + obj.getClass().getName()); }
/** * Extract a row key component as a byte[]. * * @param keyComponent a row key component expected to be either byte[] or String. * @return the row key component as a byte[]. * @throws EntityIdException if the key component is invalid. * Key components must be String or byte[]. */ private static byte[] getBytesKeyComponent(Object keyComponent) { if (keyComponent instanceof byte[]) { return (byte[]) keyComponent; } else if (keyComponent instanceof String) { return Bytes.toBytes((String) keyComponent); } else { throw new EntityIdException(String.format( "Invalid row key component: '%s', expecting byte[] or String", keyComponent)); } }
throw new EntityIdException("Invalid hbase row key"); if (format.getSalt().getSuppressKeyMaterialization()) { if (pos < hbaseRowKey.length) { throw new EntityIdException("Extra bytes in key after hash when materialization is" + "suppressed"); } catch (UnsupportedEncodingException e) { LOG.error(e.toString()); throw new EntityIdException(String.format( "UnsupportedEncoding for component %d", fijiRowElem)); buf = ByteBuffer.wrap(hbaseRowKey, pos, Integer.SIZE / Byte.SIZE); } catch (IndexOutOfBoundsException e) { throw new EntityIdException("Malformed hbase Row Key"); buf = ByteBuffer.wrap(hbaseRowKey, pos, Long.SIZE / Byte.SIZE); } catch (IndexOutOfBoundsException e) { throw new EntityIdException("Malformed hbase Row Key"); throw new EntityIdException("Extra bytes in hbase row key cannot be mapped to any " + "component"); throw new EntityIdException("Too few components decoded from hbase row key. Component " + "number " + fijiRowElem + " cannot be null");
throw new EntityIdException("Too many components in fiji Row Key"); throw new EntityIdException("Too few components in fiji Row key"); continue; } else { throw new EntityIdException("Non null component follows null component"); continue; } else { throw new EntityIdException("Unexpected null component in fiji row key." + String.format("Expected at least %d non-null components", format.getNullableStartIndex())); fijiRowKey.set(i, ((Integer) fijiRowKey.get(i)).longValue()); } else { throw new EntityIdException(String.format( "Invalid type for component %s at index %d in fijiRowKey", fijiRowKey.get(i).toString(), i));
case STRING: if (((String)fijiRowKey.get(pos)).contains("\u0000")) { throw new EntityIdException("String component cannot contain \u0000"); } catch (UnsupportedEncodingException e) { LOG.error(e.toString()); throw new EntityIdException(String.format( "UnsupportedEncoding for component %d", pos));
break; default: throw new EntityIdException("Unexpected type for Component " + componentType);
WritableUtils.writeEnum(out, Component.NULL); } else { throw new EntityIdException("Unexpected type for Component " + component.getClass().getName());