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

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

本文整理了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

/**
 * 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/org.openl.commons

public static File toTempFile(InputStream source, String fileName) {
  File file = null;
  try {
    file = File.createTempFile(fileName, null);
    IOUtils.copyAndClose(source, new FileOutputStream(file));
  } catch (IOException e) {
    final Logger log = LoggerFactory.getLogger(FileTool.class);
    log.error("Error when creating file: {}", fileName, e);
  }
  return file;
}

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

private String getTemplateFromResource(final String templatePath) throws IOException {
  InputStream inputStream;
  if (new File(templatePath).exists()) {
    inputStream = new FileInputStream(templatePath);
  } else {
    inputStream = getClass().getClassLoader().getResourceAsStream(templatePath);
  }
  return IOUtils.toStringAndClose(inputStream);
}

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

@Override
  public void close() {
    if (deployRepo instanceof Closeable) {
      // Close repo connection after validation
      IOUtils.closeQuietly((Closeable) deployRepo);
    }
  }
}

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

try {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  IOUtils.copyAndClose(inputStream, out);
  zipOutputStream.putNextEntry(entry);
  IOUtils.copy(inputStream, zipOutputStream);
  throw new ProjectException(e.getMessage(), e);
} finally {
  IOUtils.closeQuietly(zipOutputStream);

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

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

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

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

代码示例来源: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: org.openl.rules/org.openl.rules.webstudio

protected InputStream changeFileIfNeeded(String fileName, InputStream inputStream) throws ProjectException {
  if (ProjectDescriptorBasedResolvingStrategy.PROJECT_DESCRIPTOR_FILE_NAME.equals(fileName)) {
    // 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.
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
      IOUtils.copyAndClose(inputStream, outputStream);
    } catch (IOException e) {
      throw new ProjectException(e.getMessage(), e);
    }
    ByteArrayInputStream copy = new ByteArrayInputStream(outputStream.toByteArray());
    try {
      XmlProjectDescriptorSerializer serializer = new XmlProjectDescriptorSerializer(false);
      ProjectDescriptor projectDescriptor = serializer.deserialize(copy);
      projectDescriptor.setName(getProjectName());
      return IOUtils.toInputStream(serializer.serialize(projectDescriptor));
    } catch (Exception e) {
      log.warn(e.getMessage(), e);
      copy.reset();
      return copy;
    }
  } else {
    return inputStream;
  }
}

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

public static InputStream serialize(List<ProjectDescriptor> descriptors) {
  if (CollectionUtils.isEmpty(descriptors)) {
    return IOUtils.toInputStream("<descriptors/>");
  }
  StringBuilder builder = new StringBuilder("<descriptors>\n");
  for (ProjectDescriptor descriptor : descriptors) {
    builder.append("  <descriptor>\n");
    builder.append("    <projectName>").append(descriptor.getProjectName()).append("</projectName>\n");
    builder.append("    <projectVersion>").append(descriptor.getProjectVersion().getVersionName()).append(
      "</projectVersion>\n");
    builder.append("  </descriptor>\n");
  }
  builder.append("</descriptors>");
  return IOUtils.toInputStream(builder.toString());
}

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

@Override
  public void close() {
    if (deployRepo instanceof Closeable) {
      // Close repo connection after validation
      IOUtils.closeQuietly((Closeable) deployRepo);
    }
  }
}

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

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

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

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

代码示例来源: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: openl-tablets/openl-tablets

protected InputStream changeFileIfNeeded(String fileName, InputStream inputStream) throws ProjectException {
  if (ProjectDescriptorBasedResolvingStrategy.PROJECT_DESCRIPTOR_FILE_NAME.equals(fileName)) {
    // 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.
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
      IOUtils.copyAndClose(inputStream, outputStream);
    } catch (IOException e) {
      throw new ProjectException(e.getMessage(), e);
    }
    ByteArrayInputStream copy = new ByteArrayInputStream(outputStream.toByteArray());
    try {
      XmlProjectDescriptorSerializer serializer = new XmlProjectDescriptorSerializer(false);
      ProjectDescriptor projectDescriptor = serializer.deserialize(copy);
      projectDescriptor.setName(getProjectName());
      return IOUtils.toInputStream(serializer.serialize(projectDescriptor));
    } catch (Exception e) {
      log.warn(e.getMessage(), e);
      copy.reset();
      return copy;
    }
  } else {
    return inputStream;
  }
}

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

public static InputStream serialize(List<ProjectDescriptor> descriptors) {
  if (CollectionUtils.isEmpty(descriptors)) {
    return IOUtils.toInputStream("<descriptors/>");
  }
  StringBuilder builder = new StringBuilder("<descriptors>\n");
  for (ProjectDescriptor descriptor : descriptors) {
    builder.append("  <descriptor>\n");
    builder.append("    <projectName>").append(descriptor.getProjectName()).append("</projectName>\n");
    builder.append("    <projectVersion>").append(descriptor.getProjectVersion().getVersionName()).append(
      "</projectVersion>\n");
    builder.append("  </descriptor>\n");
  }
  builder.append("</descriptors>");
  return IOUtils.toInputStream(builder.toString());
}

代码示例来源: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: openl-tablets/openl-tablets

@Override
public void close() {
  IOUtils.closeQuietly(openedStream);
  openedStream = null;
}

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

return;
} finally {
  IOUtils.closeQuietly(content);
InputStream newContent = IOUtils.toInputStream(xmlString);
resource.setContent(newContent);

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

public static File toTempFile(InputStream source, String fileName) {
  File file = null;
  try {
    file = File.createTempFile(fileName, null);
    IOUtils.copyAndClose(source, new FileOutputStream(file));
  } catch (IOException e) {
    final Logger log = LoggerFactory.getLogger(FileTool.class);
    log.error("Error when creating file: {}", fileName, e);
  }
  return file;
}

相关文章