本文整理汇总了Java中org.databene.commons.IOUtil.transfer方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtil.transfer方法的具体用法?Java IOUtil.transfer怎么用?Java IOUtil.transfer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.databene.commons.IOUtil
的用法示例。
在下文中一共展示了IOUtil.transfer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeBinaryFile
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
/** Creates a binary file and writes to it all content provided by the source {@link InputStream}.
* @param filePath the path of the file to save
* @param source an {@link InputStream} which provides the content to write to the file
* @param overwrite flag which indicates if an existing file may be overwritten by the operation
* @return true if a formerly existing file was overwritten.
* @throws FunctionalFailure if a file was already present and overwriting was disabled. */
@Override
public boolean writeBinaryFile(String filePath, InputStream source, boolean overwrite) {
assertWritingPermitted("writeBinaryFile()");
File.verifyFilePath(filePath);
OutputStream out = null;
try {
FileObject target = getFileObject(filePath);
boolean existedBefore = checkWritable(target, overwrite); // NOSONAR
out = target.getContent().getOutputStream();
IOUtil.transfer(source, out);
logger.debug("Wrote binary file {}", filePath);
return existedBefore;
}
catch (IOException e) {
throw new TechnicalException("Error writing text file", e);
}
finally {
IOUtil.close(out);
}
}
示例2: readBinaryFile
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
/** Reads a binary file and provides its content as an array of bytes. */
@Override
public byte[] readBinaryFile(String filePath) {
File.verifyFilePath(filePath);
if (!exists(filePath) || isDirectory(filePath)) {
throw new AutomationException("No file exists at the given file path");
}
InputStream in = null;
try {
in = getInputStreamForFile(filePath);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtil.transfer(in, out);
logger.debug("Binary file read: {}", filePath);
return out.toByteArray();
}
catch (IOException e) {
throw new TechnicalException("Error reading binary file", e);
}
finally {
IOUtil.close(in);
}
}
示例3: redirectTo
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
public void redirectTo(OutputStream out) throws IOException {
if (!bufferedTextAvailable()) {
if (process.isRunning()) {
// expect process output
waitUntilAvailable();
}
else if (!availableWithinResponseTimeout()) {
// perform another check if process output was pending
// (necessary for Windows)
return;
}
}
InputStream bufferStream;
synchronized (buffer) {
bufferStream = new ByteArrayInputStream(this.buffer.getBytes(), this.pos, this.buffer.length() - this.pos);
}
IOUtil.transfer(bufferStream, out);
out.flush();
}
示例4: saveStreamContent
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
private void saveStreamContent(InputStream in, File tempFile) throws FileNotFoundException, IOException {
tempFile.getParentFile().mkdirs();
FileOutputStream out = null;
try {
out = new FileOutputStream(tempFile);
IOUtil.transfer(in, out);
}
finally {
IOUtil.close(out);
}
}
示例5: redirectStdInFrom
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
@Override
public void redirectStdInFrom(String processType, String processName, int processId, InputStream in) {
try {
ProcessWrapper process = getProcess(processId);
OutputStream stdIn = process.getStdIn();
IOUtil.transfer(in, stdIn);
stdIn.flush();
}
catch (IOException e) {
throw new TechnicalException("Error redirecting stdout", e);
}
}
示例6: getContentOfURI
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
public static String getContentOfURI(String uri, String encoding) throws IOException {
Reader reader = IOUtil.getReaderForURI(uri, encoding);
StringWriter writer = new StringWriter();
IOUtil.transfer(reader, writer);
IOUtil.close(reader);
IOUtil.close(writer);
return writer.toString();
}
示例7: runFromCommandLine
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
private void runFromCommandLine(String file, String database, String stage) throws IOException, InterruptedException {
String command = "benerator -Ddatabase=" + database + " -Dstage=" + stage + " " + file;
logger.debug(command);
Process process = Runtime.getRuntime().exec(command);
IOUtil.transfer(process.getInputStream(), System.out);
process.waitFor();
logger.debug(String.valueOf(process.exitValue()));
}
示例8: copySchemaTo
import org.databene.commons.IOUtil; //导入方法依赖的package包/类
private void copySchemaTo(File targetFolder) throws IOException, FileNotFoundException {
String xmlSchemaPath = BeneratorFactory.getSchemaPathForCurrentVersion();
URL schemaUrl = getClass().getClassLoader().getResource(xmlSchemaPath);
if (schemaUrl == null)
throw new FileNotFoundException("File not found: " + xmlSchemaPath);
InputStream in = schemaUrl.openStream();
File file = new File(targetFolder, xmlSchemaPath.substring(xmlSchemaPath.lastIndexOf('/')));
OutputStream out = new FileOutputStream(file);
IOUtil.transfer(in, out);
in.close();
}