Search in sources :

Example 1 with IndexWriter

use of org.apache.archiva.webdav.util.IndexWriter in project archiva by apache.

the class ArchivaDavResource method spool.

@Override
public void spool(OutputContext outputContext) throws IOException {
    if (!isCollection()) {
        outputContext.setContentLength(Files.size(localResource));
        outputContext.setContentType(mimeTypes.getMimeType(localResource.getFileName().toString()));
    }
    try {
        if (!isCollection() && outputContext.hasStream()) {
            Lock lock = fileLockManager.readFileLock(localResource);
            try (InputStream is = Files.newInputStream(lock.getFile())) {
                IOUtils.copy(is, outputContext.getOutputStream());
            }
        } else if (outputContext.hasStream()) {
            IndexWriter writer = new IndexWriter(this, localResource, logicalResource);
            writer.write(outputContext);
        }
    } catch (FileLockException e) {
        throw new IOException(e.getMessage(), e);
    } catch (FileLockTimeoutException e) {
        throw new IOException(e.getMessage(), e);
    }
}
Also used : FileLockException(org.apache.archiva.common.filelock.FileLockException) IndexWriter(org.apache.archiva.webdav.util.IndexWriter) FileLockTimeoutException(org.apache.archiva.common.filelock.FileLockTimeoutException) InputStream(java.io.InputStream) IOException(java.io.IOException) ActiveLock(org.apache.jackrabbit.webdav.lock.ActiveLock) Lock(org.apache.archiva.common.filelock.Lock)

Example 2 with IndexWriter

use of org.apache.archiva.webdav.util.IndexWriter in project archiva by apache.

the class ArchivaVirtualDavResource method spool.

@Override
public void spool(OutputContext outputContext) throws IOException {
    if (outputContext.hasStream()) {
        Collections.sort(localResources);
        List<Path> localResourceFiles = new ArrayList<>();
        for (Path resourceFile : localResources) {
            if (Files.exists(resourceFile)) {
                localResourceFiles.add(resourceFile);
            }
        }
        IndexWriter writer = new IndexWriter(this, localResourceFiles, logicalResource);
        writer.write(outputContext);
    }
}
Also used : Path(java.nio.file.Path) IndexWriter(org.apache.archiva.webdav.util.IndexWriter) ArrayList(java.util.ArrayList)

Aggregations

IndexWriter (org.apache.archiva.webdav.util.IndexWriter)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 FileLockException (org.apache.archiva.common.filelock.FileLockException)1 FileLockTimeoutException (org.apache.archiva.common.filelock.FileLockTimeoutException)1 Lock (org.apache.archiva.common.filelock.Lock)1 ActiveLock (org.apache.jackrabbit.webdav.lock.ActiveLock)1