use of org.alfresco.repo.content.ContentLimitViolationException in project alfresco-remote-api by Alfresco.
the class NodesImpl method writeContent.
private void writeContent(NodeRef nodeRef, String fileName, InputStream stream, boolean guessEncoding) {
try {
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
String mimeType = mimetypeService.guessMimetype(fileName);
if ((mimeType != null) && (!mimeType.equals(MimetypeMap.MIMETYPE_BINARY))) {
// quick/weak guess based on file extension
writer.setMimetype(mimeType);
} else {
// stronger guess based on file stream
writer.guessMimetype(fileName);
}
InputStream is = null;
if (guessEncoding) {
is = new BufferedInputStream(stream);
is.mark(1024);
writer.setEncoding(guessEncoding(is, mimeType, false));
try {
is.reset();
} catch (IOException ioe) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to reset stream after trying to guess encoding: " + ioe.getMessage());
}
}
} else {
is = stream;
}
writer.putContent(is);
} catch (ContentQuotaException cqe) {
throw new InsufficientStorageException();
} catch (ContentLimitViolationException clv) {
throw new RequestEntityTooLargeException(clv.getMessage());
} catch (ContentIOException cioe) {
if (cioe.getCause() instanceof NodeLockedException) {
throw (NodeLockedException) cioe.getCause();
}
throw cioe;
}
}
use of org.alfresco.repo.content.ContentLimitViolationException in project records-management by Alfresco.
the class FilePlanComponentsApiUtils method writeContent.
/**
* Write content to file
*
* @param nodeRef the node to write the content to
* @param fileName the name of the file (used for guessing the file's mimetype)
* @param stream the input stream to write
* @param guessEncoding whether to guess stream encoding
*/
public void writeContent(NodeRef nodeRef, String fileName, InputStream stream, boolean guessEncoding) {
try {
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
String mimeType = mimetypeService.guessMimetype(fileName);
if ((mimeType != null) && (!mimeType.equals(MimetypeMap.MIMETYPE_BINARY))) {
// quick/weak guess based on file extension
writer.setMimetype(mimeType);
} else {
// stronger guess based on file stream
writer.guessMimetype(fileName);
}
InputStream is = null;
if (guessEncoding) {
is = new BufferedInputStream(stream);
is.mark(1024);
writer.setEncoding(guessEncoding(is, mimeType, false));
try {
is.reset();
} catch (IOException ioe) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Failed to reset stream after trying to guess encoding: " + ioe.getMessage());
}
}
} else {
is = stream;
}
writer.putContent(is);
} catch (ContentQuotaException cqe) {
throw new InsufficientStorageException();
} catch (ContentLimitViolationException clv) {
throw new RequestEntityTooLargeException(clv.getMessage());
} catch (ContentIOException cioe) {
if (cioe.getCause() instanceof NodeLockedException) {
throw (NodeLockedException) cioe.getCause();
}
throw cioe;
}
}
Aggregations