本文整理匯總了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();
}