use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class MediaTypeFilter method accept.
@Override
public boolean accept(VirtualFile file) {
try (InputStream content = file.getContent()) {
TikaConfig tikaConfig = new TikaConfig();
MediaType mimeType = tikaConfig.getDetector().detect(content, new Metadata());
if (excludedMediaTypes.contains(mimeType) || excludedTypes.contains(mimeType.getType())) {
return true;
}
return false;
} catch (TikaException | ForbiddenException | ServerException | IOException e) {
return true;
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class HashSumsCounter method visit.
@Override
public void visit(VirtualFile virtualFile) throws ServerException {
if (virtualFile.isFile()) {
try (InputStream in = virtualFile.getContent()) {
final Hasher hasher = hashFunction.newHasher();
ByteStreams.copy(in, asOutputStream(hasher));
final String hexHash = hasher.hash().toString();
hashSums.add(Pair.of(hexHash, virtualFile.getPath().subPath(folder.getPath()).toString()));
} catch (IOException e) {
throw new ServerException(e);
} catch (ForbiddenException e) {
throw new ServerException(e.getServiceError());
}
} else {
for (VirtualFile child : virtualFile.getChildren()) {
child.accept(this);
}
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class TarArchiver method addTarEntry.
private void addTarEntry(VirtualFile virtualFile, TarArchiveOutputStream tarOutputStream) throws ServerException {
try {
TarArchiveEntry tarEntry = new TarArchiveEntry(getTarEntryName(virtualFile));
if (virtualFile.isFolder()) {
tarEntry.setModTime(0);
tarOutputStream.putArchiveEntry(tarEntry);
} else {
tarEntry.setSize(virtualFile.getLength());
tarEntry.setModTime(virtualFile.getLastModificationDate());
tarOutputStream.putArchiveEntry(tarEntry);
try (InputStream content = virtualFile.getContent()) {
ByteStreams.copy(content, tarOutputStream);
}
}
tarOutputStream.closeArchiveEntry();
} catch (ForbiddenException e) {
throw new ServerException(e.getServiceError());
} catch (IOException e) {
throw new ServerException(e.getMessage(), e);
}
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class DefaultFileWatcherNotificationHandler method convertToVirtualFile.
private VirtualFile convertToVirtualFile(File root, String subPath, boolean isDir) {
try {
LocalVirtualFileSystem virtualFileSystem = (LocalVirtualFileSystem) virtualFileSystemProvider.getVirtualFileSystem(true);
Path vfsPath = Path.of(subPath);
VirtualFile virtualFile = virtualFileSystem.getRoot().getChild(vfsPath);
if (virtualFile == null) {
virtualFile = new DeletedLocalVirtualFile(new File(root, subPath), ROOT.newPath(vfsPath), virtualFileSystem, isDir);
}
return virtualFile;
} catch (ServerException e) {
LOG.warn(e.getMessage());
}
return null;
}
use of org.eclipse.che.api.core.ServerException in project che by eclipse.
the class ProjectManagerWriteTest method registerImporter.
private void registerImporter(String importType, InputStream zip) throws Exception {
final ValueHolder<FolderEntry> folderHolder = new ValueHolder<>();
importerRegistry.register(new ProjectImporter() {
@Override
public String getId() {
return importType;
}
@Override
public boolean isInternal() {
return false;
}
@Override
public String getDescription() {
return "importer";
}
@Override
public void importSources(FolderEntry baseFolder, SourceStorage storage) throws ConflictException, ServerException, ForbiddenException {
importSources(baseFolder, storage, LineConsumerFactory.NULL);
}
@Override
public void importSources(FolderEntry baseFolder, SourceStorage storage, LineConsumerFactory importOutputConsumerFactory) throws ConflictException, ServerException, ForbiddenException {
// Don't really use location in this test.
baseFolder.getVirtualFile().unzip(zip, true, 0);
folderHolder.set(baseFolder);
}
@Override
public ImporterCategory getCategory() {
return ProjectImporter.ImporterCategory.ARCHIVE;
}
});
}
Aggregations