@Override public void generateFile(String fileName, String outputConfigName, CharSequence contents) throws RuntimeIOException { File file = getFile(fileName, outputConfigName); if (!getOutputConfig(outputConfigName).isOverrideExistingResources() && file.exists()) { return; } 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, encoding)); if(callBack != null) callBack.fileAdded(file); if (writeTrace) generateTrace(fileName, outputConfigName, contents); } finally { writer.close(); } } catch (IOException e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ @Override public void generateFile(String fileName, String outputCfgName, InputStream content) throws RuntimeIOException { File file = getFile(fileName, outputCfgName); if (!getOutputConfig(outputCfgName).isOverrideExistingResources() && file.exists()) { return; } try { createFolder(file.getParentFile()); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { ByteStreams.copy(content, out); } finally { try { out.close(); if(callBack != null) callBack.fileAdded(file); } finally { content.close(); } } } catch (IOException e) { throw new RuntimeIOException(e); } }
@Override public InputStream readBinaryFile(final String fileName, final String outputCfgName) throws RuntimeIOException { try { try { final URI uri = this.getURI(fileName, outputCfgName); final InputStream input = this.converter.createInputStream(uri); return this.beforeRead.beforeRead(uri, input); } catch (final Throwable _t) { if (_t instanceof FileNotFoundException) { final FileNotFoundException e = (FileNotFoundException)_t; throw new RuntimeIOException(e); } else { throw Exceptions.sneakyThrow(_t); } } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
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 */ @Override public InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException { File file = getFile(fileName, outputCfgName); try { return new BufferedInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ @Override public void generateFile(String fileName, String outputCfgName, InputStream content) { try { try { byte[] byteArray = ByteStreams.toByteArray(content); files.put(getFileName(fileName, outputCfgName), byteArray); } finally { content.close(); } } catch (IOException e) { throw new RuntimeIOException(e); } }
/** * @since 2.4 */ @Override 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); }
/** * @since 2.4 */ @Override 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); }
@Override protected IResourceDescription internalGetResourceDescription(final Resource resource, IDefaultResourceDescriptionStrategy strategy) { if (resource instanceof DerivedStateAwareResource) { DerivedStateAwareResource res = (DerivedStateAwareResource) resource; if (!res.isLoaded()) { try { res.load(res.getResourceSet().getLoadOptions()); } catch (IOException e) { throw new RuntimeIOException(e); } } boolean isInitialized = res.fullyInitialized || res.isInitializing; try { if (!isInitialized) { res.eSetDeliver(false); res.installDerivedState(true); } IResourceDescription description = createResourceDescription(resource, strategy); if (!isInitialized) { // eager initialize for (IEObjectDescription desc : description.getExportedObjects()) { desc.getEObjectURI(); } } return description; } finally { if (!isInitialized) { if (log.isDebugEnabled()) log.debug("Discarding inferred state for "+resource.getURI()); res.discardDerivedState(); res.eSetDeliver(true); } } } else { if (log.isDebugEnabled()) log.debug("Invalid configuration. DerivedStateAwareResourceDescriptionManager was registered, but resource was a " + resource.getClass().getName()); return super.internalGetResourceDescription(resource, strategy); } }
@Override public void generateFile(final String fileName, final String outputCfgName, final InputStream content) throws RuntimeIOException { try { final URI uri = this.getURI(fileName, outputCfgName); final OutputStream out = this.converter.createOutputStream(uri); try { final InputStream processedContent = this.beforeWrite.beforeWrite(uri, outputCfgName, content); ByteStreams.copy(processedContent, out); } finally { out.close(); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
@Override public CharSequence readTextFile(final String fileName, final String outputCfgName) throws RuntimeIOException { try { final URI uri = this.getURI(fileName, outputCfgName); final InputStream inputstream = this.readBinaryFile(fileName, outputCfgName); String _encoding = this.getEncoding(uri); InputStreamReader _inputStreamReader = new InputStreamReader(inputstream, _encoding); return CharStreams.toString(_inputStreamReader); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
protected void createFolder(File parent) { if (parent != null && !parent.mkdirs() && !parent.isDirectory()) throw new RuntimeIOException("Could not create directory " + parent); }
/** * {@inheritDoc} */ @Override public boolean isFile(String path, String outputConfigurationName) throws RuntimeIOException { File file = getFile(path, outputConfigurationName); return file!=null && file.exists() && file.isFile(); }
/** * @since 2.9 */ @Override public boolean isFile(String path) throws RuntimeIOException { return isFile(path, DEFAULT_OUTPUT); }
/** * Tests whether the file exists at the location denoted by the output configuration. * Returns {@code true} if the file at the described location exists and is a normal file * (not a directory). Otherwise {@code false}. * * @param path using '/' as path separator * @param outputConfigurationName the name of the output configuration * @return <code>true</code> when the file at the given path exists and is a normal file. Will return <code>false</code> when * the path belongs to a directory. */ boolean isFile (String path, String outputConfigurationName) throws RuntimeIOException;
/** * Tests whether the file exists at the location in the default output configuration. * Returns {@code true} if the file at the described location exists and is a normal file * (not a directory). Otherwise {@code false}. * * @param path using '/' as path separator * @return <code>true</code> when the file at the given path exists and is a normal file. Will return <code>false</code> when * the path belongs to a directory. */ boolean isFile (String path) throws RuntimeIOException;
/** * Writes binary data to disk. For writing text, it is recommended to use * {@link IFileSystemAccess#generateFile(String, String, CharSequence)} */ void generateFile(String fileName, String outputCfgName, InputStream content) throws RuntimeIOException;
/** * Writes binary data to disk. For writing text, it is recommended to use * {@link IFileSystemAccess#generateFile(String, CharSequence)} */ void generateFile(String fileName, InputStream content) throws RuntimeIOException;
/** * Creates an InputStream to read a binary file from disk. For text files, use {@link #readTextFile(String, String)} * . */ InputStream readBinaryFile(String fileName, String outputCfgName) throws RuntimeIOException;
/** * Creates an InputStream to read a binary file from disk. For text files, use {@link #readTextFile(String)}. */ InputStream readBinaryFile(String fileName) throws RuntimeIOException;
/** * Reads a text file from disk. To read a binary file, use {@link #readBinaryFile(String, String)}. */ CharSequence readTextFile(String fileName, String outputCfgName) throws RuntimeIOException;
/** * Reads a text file from disk. To read a binary file, use {@link #readBinaryFile(String)}. */ CharSequence readTextFile(String fileName) throws RuntimeIOException;