org.openl.util.IOUtils.toStringAndClose()方法的使用及代码示例

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

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

IOUtils.toStringAndClose介绍

[英]Get the contents of an InputStream as a String using UTF-8 character encoding and close the stream after.

This method buffers the input internally, so there is no need to use a BufferedInputStream.
[中]使用UTF-8字符编码将InputStream的内容作为字符串获取,然后关闭流。
此方法在内部缓冲输入,因此无需使用BufferedInputStream

代码示例

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

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/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.repository.jcr.modeshape

private String selectRepoID(Connection conn, CompositeConfiguration properties) throws SQLException {
  PreparedStatement statement = null;
  ResultSet rs = null;
  try {
    statement = conn.prepareStatement(properties.getString("sql.select-id"));
    statement.setString(1, OPENL_JCR_REPO_ID_KEY);
    rs = statement.executeQuery();
    if (rs.next()) {
      InputStream binaryStream = rs.getBinaryStream(1);
      return IOUtils.toStringAndClose(binaryStream);
    } else {
      return null;
    }
  } catch (IOException e) {
    log.error("Unexpected IO failure", e);
    return null;
  } finally {
    safeClose(rs);
    safeClose(statement);
  }
}

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

public String getPropertiesFileNamePatternDescription() {
  ProjectDescriptor projectDescriptor = cloneProjectDescriptor(studio.getCurrentProjectDescriptor());
  projectDescriptor.setPropertiesFileNameProcessor(propertiesFileNameProcessor);
  PropertiesFileNameProcessor processor;
  PropertiesFileNameProcessorBuilder propertiesFileNameProcessorBuilder = new PropertiesFileNameProcessorBuilder();
  try {
    processor = propertiesFileNameProcessorBuilder.build(projectDescriptor);
    Class<? extends PropertiesFileNameProcessor> processorClass = processor.getClass();
    String fileName = "/" + processorClass.getName().replace(".", "/") + ".info";
    try {
      InputStream inputStream = processorClass.getResourceAsStream(fileName);
      if (inputStream == null) {
        throw new FileNotFoundException("File '" + fileName + "' is not found");
      }
      return IOUtils.toStringAndClose(inputStream);
    } catch (FileNotFoundException e) {
      return "Description file " + fileName + " is absent";
    } catch (IOException e) {
      log.error(e.getMessage(), e);
      return "Can't load the file " + fileName;
    }
  } catch (InvalidFileNameProcessorException e) {
    return "Incorrect file name processor class '" + propertiesFileNameProcessor + "'";
  } finally {
    propertiesFileNameProcessorBuilder.destroy();
  }
}

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

public String getPropertiesFileNamePatternDescription() {
  ProjectDescriptor projectDescriptor = cloneProjectDescriptor(studio.getCurrentProjectDescriptor());
  projectDescriptor.setPropertiesFileNameProcessor(propertiesFileNameProcessor);
  PropertiesFileNameProcessor processor;
  PropertiesFileNameProcessorBuilder propertiesFileNameProcessorBuilder = new PropertiesFileNameProcessorBuilder();
  try {
    processor = propertiesFileNameProcessorBuilder.build(projectDescriptor);
    Class<? extends PropertiesFileNameProcessor> processorClass = processor.getClass();
    String fileName = "/" + processorClass.getName().replace(".", "/") + ".info";
    try {
      InputStream inputStream = processorClass.getResourceAsStream(fileName);
      if (inputStream == null) {
        throw new FileNotFoundException("File '" + fileName + "' is not found");
      }
      return IOUtils.toStringAndClose(inputStream);
    } catch (FileNotFoundException e) {
      return "Description file " + fileName + " is absent";
    } catch (IOException e) {
      log.error(e.getMessage(), e);
      return "Can't load the file " + fileName;
    }
  } catch (InvalidFileNameProcessorException e) {
    return "Incorrect file name processor class '" + propertiesFileNameProcessor + "'";
  } finally {
    propertiesFileNameProcessorBuilder.destroy();
  }
}

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

private RulesDeployGuiWrapper loadRulesDeploy(UserWorkspaceProject project) {
  try {
    AProjectResource artefact = (AProjectResource) project.getArtefact(RULES_DEPLOY_CONFIGURATION_FILE);
    InputStream content = artefact.getContent();
    String sourceString = IOUtils.toStringAndClose(content);
    return serializer.deserialize(sourceString, getSupportedVersion(project));
  } catch (IOException e) {
    FacesUtils.addErrorMessage("Cannot read " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
    log.error(e.getMessage(), e);
  } catch (ProjectException e) {
    FacesUtils.addErrorMessage("Cannot read " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
    log.error(e.getMessage(), e);
  } catch (XStreamException e) {
    FacesUtils.addErrorMessage("Cannot parse " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
    log.error(e.getMessage(), e);
  }
  return null;
}

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

private RulesDeployGuiWrapper loadRulesDeploy(UserWorkspaceProject project) {
  try {
    AProjectResource artefact = (AProjectResource) project.getArtefact(RULES_DEPLOY_CONFIGURATION_FILE);
    InputStream content = artefact.getContent();
    String sourceString = IOUtils.toStringAndClose(content);
    return serializer.deserialize(sourceString, getSupportedVersion(project));
  } catch (IOException e) {
    FacesUtils.addErrorMessage("Cannot read " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
    log.error(e.getMessage(), e);
  } catch (ProjectException e) {
    FacesUtils.addErrorMessage("Cannot read " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
    log.error(e.getMessage(), e);
  } catch (XStreamException e) {
    FacesUtils.addErrorMessage("Cannot parse " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
    log.error(e.getMessage(), e);
  }
  return null;
}

相关文章