protected void createFolder(File parent) { if (parent != null && !parent.exists() && !parent.mkdirs()) throw new RuntimeIOException("Could not create directory " + parent); }
/** * @since 2.4 */ public CharSequence readTextFile(String fileName, String outputCfgName) throws RuntimeIOException { String name = getFileName(fileName, outputCfgName); Object contents = files.get(name); if (contents == null) throw new RuntimeIOException("File not found: " + name); if (contents instanceof CharSequence) return (CharSequence) contents; if (contents instanceof byte[]) throw new RuntimeIOException("Can not read a binary file using readTextFile(). File: " + name); throw new RuntimeIOException("Unknown File Data Type: " + contents.getClass() + " File: " + name); }
/** * @since 2.4 */ public void generateFile(String fileName, String outputCfgName, InputStream content) { try { try { byte[] byteArray = ByteStreams.toByteArray(content); files.put(fileName, byteArray); } finally { content.close(); } } catch (IOException e) { throw new RuntimeIOException(e); } }
protected StringInputStream getInputStream(String contentsAsString, String encoding) { try { return new StringInputStream(contentsAsString, encoding); } catch (UnsupportedEncodingException e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException { File file = getFile(fileName, outputCfgName); try { return new FileInputStream(file); } catch (FileNotFoundException e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException { String name = getFileName(fileName, outputCfgName); Object contents = files.get(name); if (contents == null) throw new RuntimeIOException("File not found: " + name); if (contents instanceof byte[]) return new ByteArrayInputStream((byte[]) contents); if (contents instanceof CharSequence) return new StringInputStream(contents.toString()); throw new RuntimeIOException("Unknown File Data Type: " + contents.getClass() + " File: " + name); }
protected File createTempDir() { if (temporaryFolder != null && temporaryFolder.isInitialized()) { try { return temporaryFolder.newFolder(); } catch (IOException e) { throw new RuntimeIOException(e); } } return com.google.common.io.Files.createTempDir(); }
/** * @since 2.4 */ public void generateFile(String fileName, String outputCfgName, InputStream content) throws RuntimeIOException { File file = getFile(fileName, outputCfgName); try { createFolder(file.getParentFile()); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { ByteStreams.copy(content, out); } finally { try { out.close(); } finally { content.close(); } } } catch (IOException e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ public CharSequence readTextFile(String fileName, String outputCfgName) throws RuntimeIOException { try { IFile file = getFile(fileName, outputCfgName); String encoding = getEncoding(file); InputStream inputStream = file.getContents(); try { byte[] bytes = ByteStreams.toByteArray(inputStream); return new String(bytes, encoding); } finally { inputStream.close(); } } catch (IOException e) { throw new RuntimeIOException(e); } catch (CoreException e) { throw new RuntimeIOException(e); } }
@Override public void deleteFile(String fileName, String outputName) { try { IFile file = getFile(fileName, outputName); deleteFile(file, monitor); } catch (CoreException e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException { try { IFile file = getFile(fileName, outputCfgName); return file.getContents(); } catch (CoreException e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ public CharSequence readTextFile(String fileName, String outputCfgName) throws RuntimeIOException { try { File file = getFile(fileName, outputCfgName); String encoding = getEncoding(getURI(fileName, outputCfgName)); return new String(Files.toByteArray(file), encoding); } catch (UnsupportedEncodingException e) { throw new RuntimeIOException(e); } catch (IOException e) { throw new RuntimeIOException(e); } } }
/** * @since 2.4 */ protected void generateTrace(String generatedFile, String outputConfigName, CharSequence contents) { try { if (contents instanceof ITraceRegionProvider) { String traceFileName = traceFileNameProvider.getTraceFromJava(generatedFile); File traceFile = getFile(traceFileName, outputConfigName); OutputStream out = new BufferedOutputStream(new FileOutputStream(traceFile)); try { AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion(); traceSerializer.writeTraceRegionTo(traceRegion, out); } finally { out.close(); } } } catch (FileNotFoundException e) { throw new RuntimeIOException(e); } catch (IOException e) { throw new RuntimeIOException(e); } }
throw new RuntimeIOException(exception); throw new RuntimeException(exception); } catch (IOException exception) { throw new RuntimeIOException(exception);
public void generateFile(String fileName, String outputConfigName, CharSequence contents) throws RuntimeIOException { File file = getFile(fileName, outputConfigName); try { createFolder(file.getParentFile()); String encoding = getEncoding(getURI(fileName, outputConfigName)); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), encoding); try { writer.append(postProcess(fileName, outputConfigName, contents)); if (writeTrace) generateTrace(fileName, outputConfigName, contents); } finally { writer.close(); } } catch (IOException e) { throw new RuntimeIOException(e); } }
public static IFolder createSubFolder(IProject project, String folderName) throws CoreException { IFolder folder = project.getFolder(folderName); if (folder.exists()) { folder.delete(true, null); } try { return IResourcesSetupUtil.createFolder(folder.getFullPath()); } catch (Exception e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ protected boolean ensureOutputConfigurationDirectoryExists(OutputConfiguration outputConfig) { IContainer container = getContainer(outputConfig); if (!container.exists()) { if (outputConfig.isCreateOutputDirectory()) { try { createContainer(container); return true; } catch (CoreException e) { throw new RuntimeIOException(e); } } else { return false; } } return true; }
res.load(res.getResourceSet().getLoadOptions()); } catch (IOException e) { throw new RuntimeIOException(e);
throw new RuntimeIOException(e); } catch (IOException e) { throw new RuntimeIOException(e);
throw new RuntimeIOException(e); } catch (IOException e) { throw new RuntimeIOException(e);