use of org.exist.util.EXistInputSource in project exist by eXist-db.
the class RemoteCollection method storeResource.
@Override
public void storeResource(final Resource res, final Date a, final Date b) throws XMLDBException {
final Object content = (res instanceof ExtendedResource) ? ((ExtendedResource) res).getExtendedContent() : res.getContent();
if (content instanceof Path || content instanceof File || content instanceof InputSource) {
long fileLength = -1;
if (content instanceof Path) {
final Path file = (Path) content;
if (!Files.isReadable(file)) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, "Failed to read resource from file " + file.toAbsolutePath());
}
fileLength = FileUtils.sizeQuietly(file);
} else if (content instanceof File) {
final File file = (File) content;
if (!file.canRead()) {
throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, "Failed to read resource from file " + file.getAbsolutePath());
}
fileLength = file.length();
} else if (content instanceof EXistInputSource) {
fileLength = ((EXistInputSource) content).getByteStreamLength();
}
if (res instanceof AbstractRemoteResource) {
((AbstractRemoteResource) res).dateCreated = a;
((AbstractRemoteResource) res).dateModified = b;
}
if (!BinaryResource.RESOURCE_TYPE.equals(res.getResourceType()) && fileLength != -1 && fileLength < MAX_CHUNK_LENGTH) {
store((RemoteXMLResource) res);
} else {
uploadAndStore(res);
}
} else {
((AbstractRemoteResource) res).dateCreated = a;
((AbstractRemoteResource) res).dateModified = b;
if (XMLResource.RESOURCE_TYPE.equals(res.getResourceType())) {
store((RemoteXMLResource) res);
} else {
store((RemoteBinaryResource) res);
}
}
}
use of org.exist.util.EXistInputSource in project exist by eXist-db.
the class AbstractRemoteResource method setContentInternal.
protected boolean setContentInternal(final Object value) throws XMLDBException {
boolean wasSet = false;
try {
freeResources();
if (value instanceof ContentFile) {
contentFile = (ContentFile) value;
setExtendendContentLength(contentFile.size());
wasSet = true;
} else if (value instanceof Path) {
file = (Path) value;
setExtendendContentLength(Files.size(file));
wasSet = true;
} else if (value instanceof java.io.File) {
file = ((java.io.File) value).toPath();
setExtendendContentLength(Files.size(file));
wasSet = true;
} else if (value instanceof InputSource) {
inputSource = (InputSource) value;
if (inputSource instanceof EXistInputSource) {
setExtendendContentLength(((EXistInputSource) inputSource).getByteStreamLength());
}
wasSet = true;
} else if (value instanceof byte[]) {
contentFile = ByteArrayContent.of((byte[]) value);
setExtendendContentLength(contentFile.size());
wasSet = true;
} else if (value instanceof String) {
contentFile = ByteArrayContent.of((String) value);
setExtendendContentLength(contentFile.size());
wasSet = true;
}
} catch (final IOException e) {
throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e);
}
return wasSet;
}
Aggregations