Search in sources :

Example 6 with EXistInputSource

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);
        }
    }
}
Also used : Path(java.nio.file.Path) InputSource(org.xml.sax.InputSource) EXistInputSource(org.exist.util.EXistInputSource) EXistInputSource(org.exist.util.EXistInputSource) File(java.io.File)

Example 7 with EXistInputSource

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;
}
Also used : VirtualTempPath(org.exist.util.io.VirtualTempPath) Path(java.nio.file.Path) InputSource(org.xml.sax.InputSource) EXistInputSource(org.exist.util.EXistInputSource) ContentFile(org.exist.util.io.ContentFile) java.io(java.io) EXistInputSource(org.exist.util.EXistInputSource) XMLDBException(org.xmldb.api.base.XMLDBException) ContentFile(org.exist.util.io.ContentFile)

Aggregations

EXistInputSource (org.exist.util.EXistInputSource)7 Path (java.nio.file.Path)4 InputSource (org.xml.sax.InputSource)3 File (java.io.File)2 FileInputSource (org.exist.util.FileInputSource)2 XMLReaderPool (org.exist.util.XMLReaderPool)2 XMLReader (org.xml.sax.XMLReader)2 java.io (java.io)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 UnsynchronizedByteArrayInputStream (org.apache.commons.io.input.UnsynchronizedByteArrayInputStream)1 RestoreHandler (org.exist.backup.restore.RestoreHandler)1 SystemImportHandler (org.exist.backup.restore.SystemImportHandler)1 DBBroker (org.exist.storage.DBBroker)1 Txn (org.exist.storage.txn.Txn)1