use of org.eclipse.core.internal.resources.ResourceException in project che by eclipse.
the class FileUtil method transferStreams.
public static final void transferStreams(InputStream source, OutputStream destination, String path, IProgressMonitor monitor) throws CoreException {
// monitor = Policy.monitorFor(monitor);
try {
/*
* Note: although synchronizing on the buffer is thread-safe,
* it may result in slower performance in the future if we want
* to allow concurrent writes.
*/
synchronized (buffer) {
while (true) {
int bytesRead = -1;
try {
bytesRead = source.read(buffer);
} catch (IOException e) {
String msg = NLS.bind(Messages.localstore_failedReadDuringWrite, path);
throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, new Path(path), msg, e);
}
try {
if (bytesRead == -1) {
// Bug 332543 - ensure we don't ignore failures on close()
destination.close();
break;
}
destination.write(buffer, 0, bytesRead);
} catch (IOException e) {
String msg = NLS.bind(Messages.localstore_couldNotWrite, path);
throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, new Path(path), msg, e);
}
// monitor.worked(1);
}
}
} finally {
safeClose(source);
safeClose(destination);
}
}
use of org.eclipse.core.internal.resources.ResourceException in project che by eclipse.
the class Resource method unprotectedMove.
/**
* Calls the move/delete hook to perform the move. Since this method calls
* client code, it is run "unprotected", so the workspace lock is not held.
* Returns true if resources were actually moved, and false otherwise.
*/
private boolean unprotectedMove(final IResource destination, int updateFlags, IProgressMonitor monitor) throws CoreException, ResourceException {
// IMoveDeleteHook hook = workspace.getMoveDeleteHook();
switch(getType()) {
case IResource.FILE:
// if (!hook.moveFile(tree, (IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
workspace.standardMoveFile((IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
break;
case IResource.FOLDER:
// if (!hook.moveFolder(tree, (IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
workspace.standardMoveFolder((IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
break;
case IResource.PROJECT:
IProject project = (IProject) this;
// if there is no change in name, there is nothing to do so return.
if (getName().equals(destination.getName()))
return false;
IProjectDescription description = project.getDescription();
description.setName(destination.getName());
// if (!hook.moveProject(tree, project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2)))
workspace.standardMoveProject(project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork));
break;
case IResource.ROOT:
String msg = Messages.resources_moveRoot;
throw new ResourceException(new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), msg));
}
return true;
}
use of org.eclipse.core.internal.resources.ResourceException in project liferay-ide by liferay.
the class NewLiferayPluginProjectPortletNameOpTests method removePluginsSDK.
@AfterClass
public static void removePluginsSDK() throws CoreException {
IProject[] projects = CoreUtil.getAllProjects();
for (IProject project : projects) {
if (project != null && project.isAccessible() && project.exists()) {
try {
project.close(new NullProgressMonitor());
project.delete(true, new NullProgressMonitor());
} catch (ResourceException re) {
project.close(new NullProgressMonitor());
project.delete(true, new NullProgressMonitor());
}
}
}
}
use of org.eclipse.core.internal.resources.ResourceException in project polymap4-core by Polymap4.
the class Bucket method load.
/**
* Loads the contents from a file under the given directory. If <code>force</code> is
* <code>false</code>, if this bucket already contains the contents from the current location,
* avoids reloading.
*/
public void load(String newProjectName, File baseLocation, boolean force) throws CoreException {
try {
// avoid reloading
if (!force && this.location != null && baseLocation.equals(this.location.getParentFile()) && (projectName == null ? (newProjectName == null) : projectName.equals(newProjectName))) {
this.projectName = newProjectName;
return;
}
// previously loaded bucket may not have been saved... save before loading new one
save();
this.projectName = newProjectName;
this.location = new File(baseLocation, getIndexFileName());
this.entries.clear();
if (!this.location.isFile())
return;
DataInputStream source = new DataInputStream(new BufferedInputStream(new FileInputStream(location), 8192));
try {
int version = source.readByte();
if (version != getVersion()) {
// unknown version
String message = NLS.bind(Messages.resources_readMetaWrongVersion, location.getAbsolutePath(), Integer.toString(version));
ResourceStatus status = new ResourceStatus(IResourceStatus.FAILED_READ_METADATA, message);
throw new ResourceException(status);
}
int entryCount = source.readInt();
for (int i = 0; i < entryCount; i++) this.entries.put(readEntryKey(source), readEntryValue(source));
} finally {
source.close();
}
} catch (IOException ioe) {
String message = NLS.bind(Messages.resources_readMeta, location.getAbsolutePath());
ResourceStatus status = new ResourceStatus(IResourceStatus.FAILED_READ_METADATA, null, message, ioe);
throw new ResourceException(status);
}
}
use of org.eclipse.core.internal.resources.ResourceException in project polymap4-core by Polymap4.
the class Bucket method save.
/**
* Saves this bucket's contents back to its location.
*/
public void save() throws CoreException {
if (!needSaving)
return;
try {
if (entries.isEmpty()) {
needSaving = false;
cleanUp(location);
return;
}
// ensure the parent location exists
File parent = location.getParentFile();
if (parent == null)
// caught and rethrown below
throw new IOException();
parent.mkdirs();
DataOutputStream destination = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(location), 8192));
try {
destination.write(getVersion());
destination.writeInt(entries.size());
for (Iterator i = entries.entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry) i.next();
writeEntryKey(destination, (String) entry.getKey());
writeEntryValue(destination, entry.getValue());
}
} finally {
destination.close();
}
needSaving = false;
} catch (IOException ioe) {
String message = NLS.bind(Messages.resources_writeMeta, location.getAbsolutePath());
ResourceStatus status = new ResourceStatus(IResourceStatus.FAILED_WRITE_METADATA, null, message, ioe);
throw new ResourceException(status);
}
}
Aggregations