use of org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException in project OpenAM by OpenRock.
the class CompressionStrategy method reverse.
/**
* Decompress the Tokens binary object.
*
* @param blob Non null Token to modify.
*
* @throws TokenStrategyFailedException {@inheritDoc}
*/
@Override
public byte[] reverse(byte[] blob) throws TokenStrategyFailedException {
Reject.ifNull(blob);
final int lengthGuess = blob.length * 2;
final ByteArrayOutputStream bout = new ByteArrayOutputStream(lengthGuess);
try {
GZIPInputStream inputStream = new GZIPInputStream(new ByteArrayInputStream(blob));
IOUtils.copy(inputStream, bout);
inputStream.close();
} catch (IOException e) {
throw new TokenStrategyFailedException(e);
}
return bout.toByteArray();
}
use of org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException in project OpenAM by OpenRock.
the class CompressionStrategy method perform.
/**
* Compress the Tokens binary object.
*
* @param blob Non null Token to modify.
*
* @throws TokenStrategyFailedException {@inheritDoc}
*/
@Override
public byte[] perform(byte[] blob) throws TokenStrategyFailedException {
Reject.ifNull(blob);
final ByteArrayOutputStream bout = new ByteArrayOutputStream(blob.length);
try {
final GZIPOutputStream out = new GZIPOutputStream(bout);
out.write(blob);
out.flush();
out.close();
} catch (IOException e) {
throw new TokenStrategyFailedException(e);
}
return bout.toByteArray();
}
use of org.forgerock.openam.cts.utils.blob.TokenStrategyFailedException in project OpenAM by OpenRock.
the class CoreTokenAdapter method attributeQuery.
/**
* Queries the persistence layer using the given TokenFilter which must have the required
* 'return attributes' defined within it. The results of this query will consist of PartialTokens
* that match the requested CoreTokenFields.
*
* @see TokenFilter#addReturnAttribute(org.forgerock.openam.tokens.CoreTokenField)
* @see org.forgerock.openam.tokens.CoreTokenField
*
* @param filter Non null TokenFilter with return attributes defined.
* @return Non null, but possibly empty results.
* @throws CoreTokenException If there was an error performing the query.
* @throws IllegalArgumentException If the filter did not define any Return Fields.
*/
public Collection<PartialToken> attributeQuery(final TokenFilter filter) throws CoreTokenException, IllegalArgumentException {
ResultHandler<Collection<PartialToken>, CoreTokenException> handler = handlerFactory.getPartialQueryHandler();
try {
attributeQueryWithHandler(filter, handler);
Collection<PartialToken> partialTokens = handler.getResults();
Collection<PartialToken> results = new ArrayList<PartialToken>();
if (filter.getReturnFields().contains(CoreTokenField.BLOB)) {
for (PartialToken p : partialTokens) {
try {
byte[] value = p.getValue(CoreTokenField.BLOB);
results.add(new PartialToken(p, CoreTokenField.BLOB, strategy.reverse(value)));
} catch (TokenStrategyFailedException e) {
throw new CoreTokenException("Failed to reverse Blob strategy", e);
}
}
} else {
results = partialTokens;
}
debug("AttributeQuery: returned {0} Partial Tokens: {1}", results.size(), filter);
return results;
} catch (CoreTokenException e) {
throw new QueryFailedException(filter, e);
}
}
Aggregations