org.openl.util.IOUtils类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(187)

本文整理了Java中org.openl.util.IOUtils类的一些代码示例,展示了IOUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils类的具体详情如下:
包路径:org.openl.util.IOUtils
类名称:IOUtils

IOUtils介绍

[英]A set of utils to work with general IO streams.
[中]用于处理通用IO流的一组UTIL。

代码示例

代码示例来源:origin: org.openl/org.openl.commons

  1. /**
  2. * Copy bytes from <code>InputStream</code> to an <code>OutputStream</code> and close them after.
  3. * <p/>
  4. * This method uses the provided buffer, so there is no need to use a
  5. * <code>BufferedInputStream</code>.
  6. * <p/>
  7. * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
  8. *
  9. * @param input the <code>InputStream</code> to read from
  10. * @param output the <code>OutputStream</code> to write to
  11. * @throws NullPointerException if the input or output is null
  12. * @throws IOException if an I/O error occurs
  13. */
  14. public static void copyAndClose(InputStream input, OutputStream output) throws IOException {
  15. try {
  16. copy(input, output);
  17. } finally {
  18. closeQuietly(input);
  19. closeQuietly(output);
  20. }
  21. }

代码示例来源:origin: org.openl/org.openl.commons

  1. public static File toTempFile(InputStream source, String fileName) {
  2. File file = null;
  3. try {
  4. file = File.createTempFile(fileName, null);
  5. IOUtils.copyAndClose(source, new FileOutputStream(file));
  6. } catch (IOException e) {
  7. final Logger log = LoggerFactory.getLogger(FileTool.class);
  8. log.error("Error when creating file: {}", fileName, e);
  9. }
  10. return file;
  11. }

代码示例来源:origin: org.openl.rules/openl-maven-plugin

  1. private String getTemplateFromResource(final String templatePath) throws IOException {
  2. InputStream inputStream;
  3. if (new File(templatePath).exists()) {
  4. inputStream = new FileInputStream(templatePath);
  5. } else {
  6. inputStream = getClass().getClassLoader().getResourceAsStream(templatePath);
  7. }
  8. return IOUtils.toStringAndClose(inputStream);
  9. }

代码示例来源:origin: org.openl.rules/org.openl.rules.ruleservice.deployer

  1. @Override
  2. public void close() {
  3. if (deployRepo instanceof Closeable) {
  4. // Close repo connection after validation
  5. IOUtils.closeQuietly((Closeable) deployRepo);
  6. }
  7. }
  8. }

代码示例来源:origin: openl-tablets/openl-tablets

  1. try {
  2. ByteArrayOutputStream out = new ByteArrayOutputStream();
  3. IOUtils.copyAndClose(inputStream, out);
  4. zipOutputStream.putNextEntry(entry);
  5. IOUtils.copy(inputStream, zipOutputStream);
  6. throw new ProjectException(e.getMessage(), e);
  7. } finally {
  8. IOUtils.closeQuietly(zipOutputStream);

代码示例来源:origin: openl-tablets/openl-tablets

  1. projectDescriptor.getModules().add(module);
  2. String xmlString = serializer.serialize(projectDescriptor);
  3. InputStream newContent = IOUtils.toInputStream(xmlString);
  4. resource.setContent(newContent);
  5. IOUtils.closeQuietly(content);

代码示例来源:origin: org.openl.rules/org.openl.rules.webstudio

  1. String modifiedRules = serializer.serialize(projectDescriptor);
  2. IOUtils.copyAndClose(IOUtils.toInputStream(modifiedRules), new FileOutputStream(rules));
  3. } catch (Exception e) {
  4. log.warn(e.getMessage(), e);
  5. } finally {
  6. FileUtils.deleteQuietly(originalZipFolder);
  7. IOUtils.closeQuietly(modifiedZipStream);
  8. FileUtils.deleteQuietly(modifiedZip);

代码示例来源:origin: org.openl/org.openl.commons

  1. /**
  2. * Copy bytes from <code>InputStream</code> to an <code>OutputStream</code>.
  3. * <p/>
  4. * This method uses the provided buffer, so there is no need to use a
  5. * <code>BufferedInputStream</code>.
  6. * <p/>
  7. * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
  8. *
  9. * @param input the <code>InputStream</code> to read from
  10. * @param output the <code>OutputStream</code> to write to
  11. * @throws NullPointerException if the input or output is null
  12. * @throws IOException if an I/O error occurs
  13. */
  14. public static void copy(InputStream input, OutputStream output) throws IOException {
  15. copy(input, output, new byte[DEFAULT_BUFFER_SIZE]);
  16. }

代码示例来源:origin: org.openl.rules/org.openl.rules.webstudio

  1. protected InputStream changeFileIfNeeded(String fileName, InputStream inputStream) throws ProjectException {
  2. if (ProjectDescriptorBasedResolvingStrategy.PROJECT_DESCRIPTOR_FILE_NAME.equals(fileName)) {
  3. // Read the stream to memory and try to parse it and then change project name. If it can't be parsed return original rules.xml.
  4. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  5. try {
  6. IOUtils.copyAndClose(inputStream, outputStream);
  7. } catch (IOException e) {
  8. throw new ProjectException(e.getMessage(), e);
  9. }
  10. ByteArrayInputStream copy = new ByteArrayInputStream(outputStream.toByteArray());
  11. try {
  12. XmlProjectDescriptorSerializer serializer = new XmlProjectDescriptorSerializer(false);
  13. ProjectDescriptor projectDescriptor = serializer.deserialize(copy);
  14. projectDescriptor.setName(getProjectName());
  15. return IOUtils.toInputStream(serializer.serialize(projectDescriptor));
  16. } catch (Exception e) {
  17. log.warn(e.getMessage(), e);
  18. copy.reset();
  19. return copy;
  20. }
  21. } else {
  22. return inputStream;
  23. }
  24. }

代码示例来源:origin: org.openl.rules/org.openl.rules.repository

  1. public static InputStream serialize(List<ProjectDescriptor> descriptors) {
  2. if (CollectionUtils.isEmpty(descriptors)) {
  3. return IOUtils.toInputStream("<descriptors/>");
  4. }
  5. StringBuilder builder = new StringBuilder("<descriptors>\n");
  6. for (ProjectDescriptor descriptor : descriptors) {
  7. builder.append(" <descriptor>\n");
  8. builder.append(" <projectName>").append(descriptor.getProjectName()).append("</projectName>\n");
  9. builder.append(" <projectVersion>").append(descriptor.getProjectVersion().getVersionName()).append(
  10. "</projectVersion>\n");
  11. builder.append(" </descriptor>\n");
  12. }
  13. builder.append("</descriptors>");
  14. return IOUtils.toInputStream(builder.toString());
  15. }

代码示例来源:origin: openl-tablets/openl-tablets

  1. @Override
  2. public void close() {
  3. if (deployRepo instanceof Closeable) {
  4. // Close repo connection after validation
  5. IOUtils.closeQuietly((Closeable) deployRepo);
  6. }
  7. }
  8. }

代码示例来源:origin: org.openl.rules/org.openl.rules.webstudio

  1. projectDescriptor.getModules().add(module);
  2. String xmlString = serializer.serialize(projectDescriptor);
  3. InputStream newContent = IOUtils.toInputStream(xmlString);
  4. resource.setContent(newContent);
  5. IOUtils.closeQuietly(content);

代码示例来源:origin: openl-tablets/openl-tablets

  1. String modifiedRules = serializer.serialize(projectDescriptor);
  2. IOUtils.copyAndClose(IOUtils.toInputStream(modifiedRules), new FileOutputStream(rules));
  3. } catch (Exception e) {
  4. log.warn(e.getMessage(), e);
  5. } finally {
  6. FileUtils.deleteQuietly(originalZipFolder);
  7. IOUtils.closeQuietly(modifiedZipStream);
  8. FileUtils.deleteQuietly(modifiedZip);

代码示例来源:origin: openl-tablets/openl-tablets

  1. /**
  2. * Copy bytes from <code>InputStream</code> to an <code>OutputStream</code>.
  3. * <p/>
  4. * This method uses the provided buffer, so there is no need to use a
  5. * <code>BufferedInputStream</code>.
  6. * <p/>
  7. * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
  8. *
  9. * @param input the <code>InputStream</code> to read from
  10. * @param output the <code>OutputStream</code> to write to
  11. * @throws NullPointerException if the input or output is null
  12. * @throws IOException if an I/O error occurs
  13. */
  14. public static void copy(InputStream input, OutputStream output) throws IOException {
  15. copy(input, output, new byte[DEFAULT_BUFFER_SIZE]);
  16. }

代码示例来源:origin: openl-tablets/openl-tablets

  1. protected InputStream changeFileIfNeeded(String fileName, InputStream inputStream) throws ProjectException {
  2. if (ProjectDescriptorBasedResolvingStrategy.PROJECT_DESCRIPTOR_FILE_NAME.equals(fileName)) {
  3. // Read the stream to memory and try to parse it and then change project name. If it can't be parsed return original rules.xml.
  4. ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  5. try {
  6. IOUtils.copyAndClose(inputStream, outputStream);
  7. } catch (IOException e) {
  8. throw new ProjectException(e.getMessage(), e);
  9. }
  10. ByteArrayInputStream copy = new ByteArrayInputStream(outputStream.toByteArray());
  11. try {
  12. XmlProjectDescriptorSerializer serializer = new XmlProjectDescriptorSerializer(false);
  13. ProjectDescriptor projectDescriptor = serializer.deserialize(copy);
  14. projectDescriptor.setName(getProjectName());
  15. return IOUtils.toInputStream(serializer.serialize(projectDescriptor));
  16. } catch (Exception e) {
  17. log.warn(e.getMessage(), e);
  18. copy.reset();
  19. return copy;
  20. }
  21. } else {
  22. return inputStream;
  23. }
  24. }

代码示例来源:origin: openl-tablets/openl-tablets

  1. public static InputStream serialize(List<ProjectDescriptor> descriptors) {
  2. if (CollectionUtils.isEmpty(descriptors)) {
  3. return IOUtils.toInputStream("<descriptors/>");
  4. }
  5. StringBuilder builder = new StringBuilder("<descriptors>\n");
  6. for (ProjectDescriptor descriptor : descriptors) {
  7. builder.append(" <descriptor>\n");
  8. builder.append(" <projectName>").append(descriptor.getProjectName()).append("</projectName>\n");
  9. builder.append(" <projectVersion>").append(descriptor.getProjectVersion().getVersionName()).append(
  10. "</projectVersion>\n");
  11. builder.append(" </descriptor>\n");
  12. }
  13. builder.append("</descriptors>");
  14. return IOUtils.toInputStream(builder.toString());
  15. }

代码示例来源:origin: openl-tablets/openl-tablets

  1. /**
  2. * Copy bytes from <code>InputStream</code> to an <code>OutputStream</code> and close them after.
  3. * <p/>
  4. * This method uses the provided buffer, so there is no need to use a
  5. * <code>BufferedInputStream</code>.
  6. * <p/>
  7. * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
  8. *
  9. * @param input the <code>InputStream</code> to read from
  10. * @param output the <code>OutputStream</code> to write to
  11. * @throws NullPointerException if the input or output is null
  12. * @throws IOException if an I/O error occurs
  13. */
  14. public static void copyAndClose(InputStream input, OutputStream output) throws IOException {
  15. try {
  16. copy(input, output);
  17. } finally {
  18. closeQuietly(input);
  19. closeQuietly(output);
  20. }
  21. }

代码示例来源:origin: openl-tablets/openl-tablets

  1. @Override
  2. public void close() {
  3. IOUtils.closeQuietly(openedStream);
  4. openedStream = null;
  5. }

代码示例来源:origin: org.openl.rules/org.openl.rules.webstudio

  1. return;
  2. } finally {
  3. IOUtils.closeQuietly(content);
  4. InputStream newContent = IOUtils.toInputStream(xmlString);
  5. resource.setContent(newContent);

代码示例来源:origin: openl-tablets/openl-tablets

  1. public static File toTempFile(InputStream source, String fileName) {
  2. File file = null;
  3. try {
  4. file = File.createTempFile(fileName, null);
  5. IOUtils.copyAndClose(source, new FileOutputStream(file));
  6. } catch (IOException e) {
  7. final Logger log = LoggerFactory.getLogger(FileTool.class);
  8. log.error("Error when creating file: {}", fileName, e);
  9. }
  10. return file;
  11. }

相关文章