Search in sources :

Example 1 with BulkUploadException

use of org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException in project vorto by eclipse.

the class VortoModelImporter method copyStream.

private static byte[] copyStream(ZipInputStream in, ZipEntry entry) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        int size;
        byte[] buffer = new byte[2048];
        BufferedOutputStream bos = new BufferedOutputStream(out);
        while ((size = in.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
    } catch (IOException e) {
        throw new BulkUploadException("IOException while copying stream to ZipEntry", e);
    }
    return out.toByteArray();
}
Also used : BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with BulkUploadException

use of org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException in project vorto by eclipse.

the class AbstractModelImporter method getUploadedFilesFromZip.

protected Collection<FileUpload> getUploadedFilesFromZip(byte[] uploadedFile) {
    Collection<FileUpload> fileUploads = new ArrayList<>();
    ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(uploadedFile));
    ZipEntry entry = null;
    try {
        while ((entry = zis.getNextEntry()) != null) {
            if (!entry.isDirectory() && !entry.getName().substring(entry.getName().lastIndexOf("/") + 1).startsWith(".")) {
                fileUploads.add(FileUpload.create(entry.getName(), ZipUtils.copyStream(zis, entry)));
            }
        }
    } catch (IOException e) {
        throw new BulkUploadException("Problem while reading zip file during validation", e);
    }
    return fileUploads;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException) IOException(java.io.IOException)

Example 3 with BulkUploadException

use of org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException in project vorto by eclipse.

the class BulkUploadHelper method getFileContentsFromZip.

private Collection<FileContent> getFileContentsFromZip(byte[] content) {
    Collection<FileContent> fileContents = new ArrayList<>();
    ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(content));
    ZipEntry entry = null;
    try {
        while ((entry = zis.getNextEntry()) != null) {
            if (!entry.isDirectory() && ModelParserFactory.hasParserFor(entry.getName())) {
                fileContents.add(new FileContent(entry.getName(), copyStream(zis)));
            }
        }
    } catch (IOException e) {
        throw new BulkUploadException("IOException while getting next entry from zip file", e);
    }
    return fileContents;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(java.util.zip.ZipEntry) BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException) IOException(java.io.IOException)

Example 4 with BulkUploadException

use of org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException in project vorto by eclipse.

the class ZipUtils method copyStream.

public static byte[] copyStream(ZipInputStream in, ZipEntry entry) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        int size;
        byte[] buffer = new byte[2048];
        BufferedOutputStream bos = new BufferedOutputStream(out);
        while ((size = in.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
    } catch (IOException e) {
        throw new BulkUploadException("IOException while copying stream to ZipEntry", e);
    }
    return out.toByteArray();
}
Also used : BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 5 with BulkUploadException

use of org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException in project vorto by eclipse.

the class VortoModelImporter method getFileContents.

private Collection<FileContent> getFileContents(FileUpload fileUpload) {
    Collection<FileContent> fileContents = new ArrayList<>();
    ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(fileUpload.getContent()));
    ZipEntry entry = null;
    try {
        while ((entry = zis.getNextEntry()) != null) {
            if (!entry.isDirectory() && ModelParserFactory.hasParserFor(entry.getName())) {
                fileContents.add(new FileContent(entry.getName(), copyStream(zis, entry)));
            }
        }
    } catch (IOException e) {
        throw new BulkUploadException("IOException while getting next entry from zip file", e);
    }
    return fileContents;
}
Also used : FileContent(org.eclipse.vorto.repository.core.FileContent) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) BulkUploadException(org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)7 BulkUploadException (org.eclipse.vorto.repository.web.core.exceptions.BulkUploadException)7 BufferedOutputStream (java.io.BufferedOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ZipEntry (java.util.zip.ZipEntry)3 ZipInputStream (java.util.zip.ZipInputStream)3 ArrayList (java.util.ArrayList)2 FileContent (org.eclipse.vorto.repository.core.FileContent)1 ValidationReport (org.eclipse.vorto.repository.importer.ValidationReport)1