use of org.alfresco.service.cmr.repository.TransformationOptionPair in project alfresco-repository by Alfresco.
the class TransformerConfigLimits method setTransformationLimitsFromProperties.
/**
* Sets a TransformationOptionLimits value. This may be a size in K bytes,
* a time in ms or number of pages. It may also be a maximum or limit value.
* When the maximum and limit are both set and the same, the maximum value
* wins.
*/
private void setTransformationLimitsFromProperties(TransformationOptionLimits limits, String value, String suffix) {
long newValue = Long.parseLong(value);
TransformationOptionPair optionPair = suffix == TransformerConfig.MAX_SOURCE_SIZE_K_BYTES || suffix == TransformerConfig.READ_LIMIT_K_BYTES ? limits.getKBytesPair() : suffix == TransformerConfig.TIMEOUT_MS || suffix == TransformerConfig.READ_LIMIT_TIME_MS ? limits.getTimePair() : limits.getPagesPair();
// If max rather than limit value
if (suffix == TransformerConfig.MAX_SOURCE_SIZE_K_BYTES || suffix == TransformerConfig.TIMEOUT_MS || suffix == TransformerConfig.MAX_PAGES) {
long limit = optionPair.getLimit();
if (limit < 0 || limit >= newValue) {
optionPair.setLimit(-1, NOT_THROWN_MESSAGE);
optionPair.setMax(newValue, NOT_THROWN_MESSAGE);
}
} else {
long max = optionPair.getMax();
if (max < 0 || max > newValue) {
optionPair.setMax(-1, NOT_THROWN_MESSAGE);
optionPair.setLimit(newValue, NOT_THROWN_MESSAGE);
}
}
}
use of org.alfresco.service.cmr.repository.TransformationOptionPair in project alfresco-repository by Alfresco.
the class TextToPdfContentTransformer method transformLocal.
@Override
protected void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception {
PDDocument pdf = null;
InputStream is = null;
InputStreamReader ir = null;
OutputStream os = null;
try {
is = reader.getContentInputStream();
ir = buildReader(is, reader.getEncoding(), reader.getContentUrl());
TransformationOptionLimits limits = getLimits(reader, writer, options);
TransformationOptionPair pageLimits = limits.getPagesPair();
pdf = transformer.createPDFFromText(ir, pageLimits, reader.getContentUrl(), transformerDebug);
// dump it all to the writer
os = writer.getContentOutputStream();
pdf.save(os);
} finally {
if (pdf != null) {
try {
pdf.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
if (ir != null) {
try {
ir.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
if (is != null) {
try {
is.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
if (os != null) {
try {
os.close();
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
use of org.alfresco.service.cmr.repository.TransformationOptionPair in project alfresco-repository by Alfresco.
the class TextToPdfContentTransformer method transformRemote.
@Override
protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader, ContentWriter writer, TransformationOptions options, String sourceMimetype, String targetMimetype, String sourceExtension, String targetExtension, String targetEncoding) throws Exception {
String sourceEncoding = reader.getEncoding();
long timeoutMs = options.getTimeoutMs();
TransformationOptionLimits limits = getLimits(reader, writer, options);
TransformationOptionPair pageLimits = limits.getPagesPair();
int pageLimit = (int) pageLimits.getValue();
remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension, timeoutMs, logger, "transformName", "textToPdf", "sourceMimetype", sourceMimetype, "targetMimetype", targetMimetype, "targetExtension", targetExtension, SOURCE_ENCODING, sourceEncoding, "pageLimit", String.valueOf(pageLimit));
}
use of org.alfresco.service.cmr.repository.TransformationOptionPair in project alfresco-repository by Alfresco.
the class AbstractContentReader method getContentInputStream.
/**
* @see Channels#newInputStream(java.nio.channels.ReadableByteChannel)
*/
public InputStream getContentInputStream() throws ContentIOException {
try {
ReadableByteChannel channel = getReadableChannel();
InputStream is = Channels.newInputStream(channel);
// If we have a timeout or read limit, intercept the calls.
if (limits != null) {
TransformationOptionPair time = limits.getTimePair();
TransformationOptionPair kBytes = limits.getKBytesPair();
long timeoutMs = time.getValue();
long readLimitBytes = kBytes.getValue() * 1024;
if (timeoutMs > 0 || readLimitBytes > 0) {
Action timeoutAction = time.getAction();
Action readLimitAction = kBytes.getAction();
is = new TimeSizeRestrictedInputStream(is, timeoutMs, timeoutAction, readLimitBytes, readLimitAction, transformerDebug);
}
}
is = new BufferedInputStream(is);
// done
return is;
} catch (Throwable e) {
throw new ContentIOException("Failed to open stream onto channel: \n" + " accessor: " + this, e);
}
}
Aggregations