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();
}
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;
}
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;
}
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();
}
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;
}
Aggregations