use of org.apache.commons.codec.DecoderException in project databus by linkedin.
the class GGEventGenerationFactory method convertToSimpleType.
public static Object convertToSimpleType(String fieldValue, Schema.Field avroField) throws DatabusException {
String databaseFieldType = SchemaHelper.getMetaField(avroField, "dbFieldType");
String recordFieldName = avroField.name();
// return int
if (databaseFieldType.equalsIgnoreCase("INTEGER")) {
return new Integer(fieldValue);
} else // return long
if (databaseFieldType.equalsIgnoreCase("LONG")) {
return new Long(fieldValue);
} else if (databaseFieldType.equalsIgnoreCase("DATE")) {
return ggDateStringToLong(fieldValue);
} else if (databaseFieldType.equalsIgnoreCase("TIMESTAMP")) {
return ggTimeStampStringToMilliSeconds(fieldValue);
} else // return float
if (databaseFieldType.equalsIgnoreCase("FLOAT")) {
return new Float(fieldValue);
} else // return double
if (databaseFieldType.equalsIgnoreCase("DOUBLE")) {
return new Double(fieldValue);
} else // return string
if (databaseFieldType.equalsIgnoreCase("CLOB")) {
return fieldValue;
} else if (databaseFieldType.equalsIgnoreCase("VARCHAR")) {
return fieldValue;
} else if (databaseFieldType.equalsIgnoreCase("VARCHAR2")) {
return fieldValue;
} else if (databaseFieldType.equalsIgnoreCase("NVARCHAR")) {
return fieldValue;
} else if (databaseFieldType.equalsIgnoreCase("NVARCHAR2")) {
return fieldValue;
} else if (databaseFieldType.equalsIgnoreCase("XMLTYPE")) {
return fieldValue;
} else if (databaseFieldType.equalsIgnoreCase("CHAR")) {
return fieldValue;
} else // return bytes
if (databaseFieldType.equalsIgnoreCase("BLOB") || databaseFieldType.equalsIgnoreCase("RAW")) {
if (fieldValue.length() == 0) {
return fieldValue.getBytes(Charset.defaultCharset());
}
if (fieldValue.length() <= 2) {
throw new DatabusException("Unable to decode the string because length is less than 2");
}
if (!isStringHex(fieldValue)) {
throw new DatabusException("Unable to decode the string because it is not hex-encoded");
}
try {
return stringToHex(fieldValue.substring(2, fieldValue.length() - 1));
} catch (DecoderException e) {
throw new DatabusException("Unable to decode a " + databaseFieldType + " field: " + recordFieldName);
}
} else // return array
if (databaseFieldType.equalsIgnoreCase("ARRAY")) {
// TODO add support for array
throw new DatabusException("ARRAY type still not implemented!");
} else // return record
if (databaseFieldType.equalsIgnoreCase("TABLE")) {
// TODO add support for table
throw new DatabusException("TABLE type still not implemented!");
} else {
throw new DatabusException("unknown field type: " + recordFieldName + ":" + databaseFieldType);
}
}
use of org.apache.commons.codec.DecoderException in project v7files by thiloplanz.
the class CatCommand method main.
public static void main(String[] args) throws MongoException, IOException {
if (args.length != 3) {
System.err.println("Output the contents of a file:");
System.err.println(" by name: cat <root> <path>");
System.err.println(" by hash: cat -sha <shaHex>");
System.exit(1);
}
if ("-sha".equals(args[1])) {
MongoContentStorage storage = new MongoContentStorage(Configuration.getMongo().getDB(Configuration.getProperty("mongo.db")));
String sha = args[2];
try {
Content file = findContentByPrefix(storage, sha);
if (file == null) {
System.err.println("file not found");
System.exit(1);
}
IOUtils.copy(file.getInputStream(), System.out);
} catch (DecoderException e) {
System.err.println("invalid parameter :" + sha + " is not a hex-encoded SHA-1 prefix");
System.exit(1);
}
} else {
V7GridFS fs = new V7GridFS(Configuration.getMongo().getDB(Configuration.getProperty("mongo.db")));
String root = args[1];
String path = args[2];
String[] fullPath = ArrayUtils.add(StringUtils.split(path, '/'), 0, root);
V7File file = fs.getFile(fullPath);
if (file == null) {
System.err.println("file not found");
System.exit(1);
}
IOUtils.copy(file.getInputStream(), System.out);
}
}
use of org.apache.commons.codec.DecoderException in project crate by crate.
the class ExceptionsHelperTests method testMaybeError.
@Test
public void testMaybeError() {
final Error outOfMemoryError = new OutOfMemoryError();
assertError(outOfMemoryError, outOfMemoryError);
final DecoderException decoderException = new DecoderException(outOfMemoryError);
assertError(decoderException, outOfMemoryError);
final Exception e = new Exception();
e.addSuppressed(decoderException);
assertError(e, outOfMemoryError);
final int depth = randomIntBetween(1, 16);
Throwable cause = new Exception();
boolean fatal = false;
Error error = null;
for (int i = 0; i < depth; i++) {
final int length = randomIntBetween(1, 4);
for (int j = 0; j < length; j++) {
if (!fatal && rarely()) {
error = new Error();
cause.addSuppressed(error);
fatal = true;
} else {
cause.addSuppressed(new Exception());
}
}
if (!fatal && rarely()) {
cause = error = new Error(cause);
fatal = true;
} else {
cause = new Exception(cause);
}
}
if (fatal) {
assertError(cause, error);
} else {
assertFalse(maybeError(cause).isPresent());
}
assertFalse(maybeError(new Exception(new DecoderException())).isPresent());
}
use of org.apache.commons.codec.DecoderException in project alluxio by Alluxio.
the class ListBucketResult method decodeToken.
/**
* Decode a continuation token which is used in get Bucket.
* @param token used to decode to a key
* @return if token is not null return decoded key, otherwise returns null
* @throws S3Exception
*/
public static String decodeToken(String token) throws S3Exception {
if (token != null && token.length() > 0) {
int indexSeparator = token.indexOf(CONTINUATION_TOKEN_SEPARATOR);
if (indexSeparator == -1) {
throw new S3Exception(token, S3ErrorCode.INVALID_CONTINUATION_TOKEN);
}
String hex = token.substring(0, indexSeparator);
String digest = token.substring(indexSeparator + 1);
String digestActualKey = DigestUtils.sha256Hex(hex);
if (!digest.equals(digestActualKey)) {
throw new S3Exception(token, S3ErrorCode.INVALID_CONTINUATION_TOKEN);
}
try {
ByteBuffer buffer = ByteBuffer.wrap(Hex.decodeHex(hex));
return new String(buffer.array(), StandardCharsets.UTF_8);
} catch (DecoderException e) {
throw new S3Exception(e, token, S3ErrorCode.INVALID_CONTINUATION_TOKEN);
}
} else {
return "";
}
}
use of org.apache.commons.codec.DecoderException in project hadoop by apache.
the class FSEditLogOp method delegationKeyFromXml.
public static DelegationKey delegationKeyFromXml(Stanza st) throws InvalidXmlException {
int keyId = Integer.parseInt(st.getValue("KEY_ID"));
long expiryDate = Long.parseLong(st.getValue("EXPIRY_DATE"));
byte[] key = null;
try {
key = Hex.decodeHex(st.getValue("KEY").toCharArray());
} catch (DecoderException e) {
throw new InvalidXmlException(e.toString());
} catch (InvalidXmlException e) {
}
return new DelegationKey(keyId, expiryDate, key);
}
Aggregations