本文整理了Java中org.openl.util.IOUtils.copy()
方法的一些代码示例,展示了IOUtils.copy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.copy()
方法的具体详情如下:
包路径:org.openl.util.IOUtils
类名称:IOUtils
方法名:copy
[英]Copy bytes from InputStream
to an OutputStream
.
This method uses the provided buffer, so there is no need to use a BufferedInputStream
.
The buffer size is given by #DEFAULT_BUFFER_SIZE.
[中]将字节从InputStream
复制到OutputStream
。
此方法使用提供的缓冲区,因此不需要使用BufferedInputStream
。
缓冲区大小由#默认_buffer_size给出。
代码示例来源:origin: org.openl/org.openl.commons
/**
* Copy bytes from <code>InputStream</code> to an <code>OutputStream</code>.
* <p/>
* This method uses the provided buffer, so there is no need to use a
* <code>BufferedInputStream</code>.
* <p/>
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
*
* @param input the <code>InputStream</code> to read from
* @param output the <code>OutputStream</code> to write to
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
*/
public static void copy(InputStream input, OutputStream output) throws IOException {
copy(input, output, new byte[DEFAULT_BUFFER_SIZE]);
}
代码示例来源:origin: openl-tablets/openl-tablets
/**
* Copy bytes from <code>InputStream</code> to an <code>OutputStream</code>.
* <p/>
* This method uses the provided buffer, so there is no need to use a
* <code>BufferedInputStream</code>.
* <p/>
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
*
* @param input the <code>InputStream</code> to read from
* @param output the <code>OutputStream</code> to write to
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
*/
public static void copy(InputStream input, OutputStream output) throws IOException {
copy(input, output, new byte[DEFAULT_BUFFER_SIZE]);
}
代码示例来源:origin: org.openl/org.openl.commons
private static void archiveFile(File file, String name, ZipOutputStream zos, byte[] data) throws IOException {
FileInputStream fis = new FileInputStream(file);
try {
ZipEntry entry = new ZipEntry(name);
zos.putNextEntry(entry);
IOUtils.copy(fis, zos, data);
} finally {
fis.close();
}
}
}
代码示例来源:origin: openl-tablets/openl-tablets
private static void archiveFile(File file, String name, ZipOutputStream zos, byte[] data) throws IOException {
FileInputStream fis = new FileInputStream(file);
try {
ZipEntry entry = new ZipEntry(name);
zos.putNextEntry(entry);
IOUtils.copy(fis, zos, data);
} finally {
fis.close();
}
}
}
代码示例来源:origin: org.openl.rules/org.openl.rules.repository
private FileItem createFileItem(ResultSet rs) throws SQLException {
FileData fileData = createFileData(rs);
InputStream data = rs.getBinaryStream("file_data");
if (data == null) {
return null;
}
// ResultSet will be closed, so InputStream can be closed too, that's
// why copy it to byte array before.
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
IOUtils.copy(data, out);
} catch (IOException e) {
throw new SQLException(e);
}
return new FileItem(fileData, new ByteArrayInputStream(out.toByteArray()));
}
代码示例来源:origin: org.openl/org.openl.commons
/**
* Get the contents of an <code>InputStream</code> as a String using UTF-8 character encoding
* and close the stream after.
* <p/>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from
* @return the requested String
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
*/
public static String toStringAndClose(InputStream input) throws IOException {
try {
StringWriter writer = new StringWriter();
Reader reader = new InputStreamReader(input, StringUtils.UTF_8);
copy(reader, writer);
return writer.toString();
} finally {
closeQuietly(input);
}
}
代码示例来源:origin: openl-tablets/openl-tablets
/**
* Get the contents of an <code>InputStream</code> as a String using UTF-8 character encoding
* and close the stream after.
* <p/>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from
* @return the requested String
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
*/
public static String toStringAndClose(InputStream input) throws IOException {
try {
StringWriter writer = new StringWriter();
Reader reader = new InputStreamReader(input, StringUtils.UTF_8);
copy(reader, writer);
return writer.toString();
} finally {
closeQuietly(input);
}
}
代码示例来源:origin: openl-tablets/openl-tablets
private FileItem createFileItem(ResultSet rs) throws SQLException {
FileData fileData = createFileData(rs);
InputStream data = rs.getBinaryStream("file_data");
if (data == null) {
return null;
}
// ResultSet will be closed, so InputStream can be closed too, that's
// why copy it to byte array before.
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
IOUtils.copy(data, out);
} catch (IOException e) {
throw new SQLException(e);
}
return new FileItem(fileData, new ByteArrayInputStream(out.toByteArray()));
}
代码示例来源:origin: openl-tablets/openl-tablets
private static void packFile(ZipOutputStream zipOutputStream, AProjectResource file) throws IOException, ProjectException {
ZipEntry entry = new ZipEntry(file.getInternalPath());
zipOutputStream.putNextEntry(entry);
InputStream source = null;
try {
source = file.getContent();
IOUtils.copy(source, zipOutputStream);
} finally {
if (source != null) {
source.close();
}
}
zipOutputStream.closeEntry();
}
代码示例来源:origin: openl-tablets/openl-tablets
@Override
public FileData save(FileData data, InputStream stream) throws IOException {
String name = data.getName();
File file = new File(root, name);
file.getParentFile().mkdirs();
FileOutputStream output = null;
try {
output = new FileOutputStream(file);
IOUtils.copy(stream, output);
} finally {
// Close only output stream. This class isn't responsible for input stream: stream must be closed in the
// place where it was created.
IOUtils.closeQuietly(output);
}
return getFileData(file);
}
代码示例来源:origin: org.openl.rules/org.openl.rules.repository
@Override
public FileData save(FileData data, InputStream stream) throws IOException {
String name = data.getName();
File file = new File(root, name);
file.getParentFile().mkdirs();
FileOutputStream output = null;
try {
output = new FileOutputStream(file);
IOUtils.copy(stream, output);
} finally {
// Close only output stream. This class isn't responsible for input stream: stream must be closed in the
// place where it was created.
IOUtils.closeQuietly(output);
}
return getFileData(file);
}
代码示例来源:origin: openl-tablets/openl-tablets
public static void writeOutContent(final HttpServletResponse res, final File content, final String filename) {
if (content == null) {
return;
}
FileInputStream input = null;
try {
res.setHeader("Pragma", "no-cache");
res.setDateHeader("Expires", 0);
res.setContentType("application/" + FileUtils.getExtension(filename));
WebTool.setContentDisposition(res, filename);
input = new FileInputStream(content);
IOUtils.copy(input, res.getOutputStream());
} catch (final IOException e) {
String msg = "Failed to write content of '" + content.getAbsolutePath() + "' into response!";
final Logger log = LoggerFactory.getLogger(ExportFile.class);
log.error(msg, e);
FacesUtils.addErrorMessage(msg, e.getMessage());
} finally {
IOUtils.closeQuietly(input);
}
}
}
代码示例来源:origin: openl-tablets/openl-tablets
public void setContent(InputStream inputStream) throws ProjectException {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(source);
IOUtils.copy(inputStream, fos);
notifyModified();
} catch (IOException e) {
throw new ProjectException("Failed to set content.", e);
} finally {
IOUtils.closeQuietly(fos);
}
}
代码示例来源:origin: org.openl.rules/org.openl.rules.webstudio
public static void writeOutContent(final HttpServletResponse res, final File content, final String filename) {
if (content == null) {
return;
}
FileInputStream input = null;
try {
res.setHeader("Pragma", "no-cache");
res.setDateHeader("Expires", 0);
res.setContentType("application/" + FileUtils.getExtension(filename));
WebTool.setContentDisposition(res, filename);
input = new FileInputStream(content);
IOUtils.copy(input, res.getOutputStream());
} catch (final IOException e) {
String msg = "Failed to write content of '" + content.getAbsolutePath() + "' into response!";
final Logger log = LoggerFactory.getLogger(ExportFile.class);
log.error(msg, e);
FacesUtils.addErrorMessage(msg, e.getMessage());
} finally {
IOUtils.closeQuietly(input);
}
}
}
代码示例来源:origin: org.openl/org.openl.commons
/**
* Copy bytes from <code>InputStream</code> to an <code>OutputStream</code> and close them after.
* <p/>
* This method uses the provided buffer, so there is no need to use a
* <code>BufferedInputStream</code>.
* <p/>
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
*
* @param input the <code>InputStream</code> to read from
* @param output the <code>OutputStream</code> to write to
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
*/
public static void copyAndClose(InputStream input, OutputStream output) throws IOException {
try {
copy(input, output);
} finally {
closeQuietly(input);
closeQuietly(output);
}
}
代码示例来源:origin: openl-tablets/openl-tablets
/**
* Copy bytes from <code>InputStream</code> to an <code>OutputStream</code> and close them after.
* <p/>
* This method uses the provided buffer, so there is no need to use a
* <code>BufferedInputStream</code>.
* <p/>
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
*
* @param input the <code>InputStream</code> to read from
* @param output the <code>OutputStream</code> to write to
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
*/
public static void copyAndClose(InputStream input, OutputStream output) throws IOException {
try {
copy(input, output);
} finally {
closeQuietly(input);
closeQuietly(output);
}
}
代码示例来源:origin: org.openl.rules/org.openl.rules.repository.jcr
private void writeFolderToZip(FolderAPI folder, ZipOutputStream zipOutputStream, String pathPrefix) throws
IOException,
ProjectException {
Collection<? extends ArtefactAPI> artefacts = folder.getArtefacts();
for (ArtefactAPI artefact : artefacts) {
if (artefact instanceof ResourceAPI) {
ZipEntry entry = new ZipEntry(pathPrefix + artefact.getName());
zipOutputStream.putNextEntry(entry);
InputStream content = ((ResourceAPI) artefact).getContent();
IOUtils.copy(content, zipOutputStream);
content.close();
zipOutputStream.closeEntry();
} else {
writeFolderToZip((FolderAPI) artefact, zipOutputStream, pathPrefix + artefact.getName() + "/");
}
}
}
代码示例来源:origin: openl-tablets/openl-tablets
private void writeFolderToZip(FolderAPI folder, ZipOutputStream zipOutputStream, String pathPrefix) throws
IOException,
ProjectException {
Collection<? extends ArtefactAPI> artefacts = folder.getArtefacts();
for (ArtefactAPI artefact : artefacts) {
if (artefact instanceof ResourceAPI) {
ZipEntry entry = new ZipEntry(pathPrefix + artefact.getName());
zipOutputStream.putNextEntry(entry);
InputStream content = ((ResourceAPI) artefact).getContent();
IOUtils.copy(content, zipOutputStream);
content.close();
zipOutputStream.closeEntry();
} else {
writeFolderToZip((FolderAPI) artefact, zipOutputStream, pathPrefix + artefact.getName() + "/");
}
}
}
代码示例来源:origin: openl-tablets/openl-tablets
private void writeArtefact(ZipOutputStream zipOutputStream, AProjectArtefact artefact) throws
IOException,
ProjectException {
if ((artefact instanceof AProjectResource)) {
AProjectResource resource = (AProjectResource) artefact;
zipOutputStream.putNextEntry(new ZipEntry(resource.getInternalPath()));
ResourceTransformer transformer = getResourceTransformer();
InputStream content = transformer != null ? transformer.transform(resource) : resource.getContent();
IOUtils.copy(content, zipOutputStream);
content.close();
zipOutputStream.closeEntry();
} else {
AProjectFolder folder = (AProjectFolder) artefact;
for (AProjectArtefact a : folder.getArtefacts()) {
writeArtefact(zipOutputStream, a);
}
}
}
代码示例来源:origin: openl-tablets/openl-tablets
private void archiveAndSave(FolderRepository designRepo, String projectPath, String version, Repository deployRepo, FileData dest) throws ProjectException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zipOutputStream = null;
try {
zipOutputStream = new ZipOutputStream(out);
List<FileData> files = designRepo.listFiles(projectPath, version);
for (FileData file : files) {
String internalPath = file.getName().substring(projectPath.length());
zipOutputStream.putNextEntry(new ZipEntry(internalPath));
FileItem fileItem = designRepo.readHistory(file.getName(), file.getVersion());
try (InputStream content = fileItem.getStream()) {
IOUtils.copy(content, zipOutputStream);
}
zipOutputStream.closeEntry();
}
zipOutputStream.finish();
dest.setSize(out.size());
deployRepo.save(dest, new ByteArrayInputStream(out.toByteArray()));
} catch (IOException e) {
throw new ProjectException(e.getMessage(), e);
} finally {
IOUtils.closeQuietly(zipOutputStream);
}
}
内容来源于网络,如有侵权,请联系作者删除!