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

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

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

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

  1. private String selectRepoID(Connection conn, CompositeConfiguration properties) throws SQLException {
  2. PreparedStatement statement = null;
  3. ResultSet rs = null;
  4. try {
  5. statement = conn.prepareStatement(properties.getString("sql.select-id"));
  6. statement.setString(1, OPENL_JCR_REPO_ID_KEY);
  7. rs = statement.executeQuery();
  8. if (rs.next()) {
  9. InputStream binaryStream = rs.getBinaryStream(1);
  10. return IOUtils.toStringAndClose(binaryStream);
  11. } else {
  12. return null;
  13. }
  14. } catch (IOException e) {
  15. log.error("Unexpected IO failure", e);
  16. return null;
  17. } finally {
  18. safeClose(rs);
  19. safeClose(statement);
  20. }
  21. }

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

  1. public String getPropertiesFileNamePatternDescription() {
  2. ProjectDescriptor projectDescriptor = cloneProjectDescriptor(studio.getCurrentProjectDescriptor());
  3. projectDescriptor.setPropertiesFileNameProcessor(propertiesFileNameProcessor);
  4. PropertiesFileNameProcessor processor;
  5. PropertiesFileNameProcessorBuilder propertiesFileNameProcessorBuilder = new PropertiesFileNameProcessorBuilder();
  6. try {
  7. processor = propertiesFileNameProcessorBuilder.build(projectDescriptor);
  8. Class<? extends PropertiesFileNameProcessor> processorClass = processor.getClass();
  9. String fileName = "/" + processorClass.getName().replace(".", "/") + ".info";
  10. try {
  11. InputStream inputStream = processorClass.getResourceAsStream(fileName);
  12. if (inputStream == null) {
  13. throw new FileNotFoundException("File '" + fileName + "' is not found");
  14. }
  15. return IOUtils.toStringAndClose(inputStream);
  16. } catch (FileNotFoundException e) {
  17. return "Description file " + fileName + " is absent";
  18. } catch (IOException e) {
  19. log.error(e.getMessage(), e);
  20. return "Can't load the file " + fileName;
  21. }
  22. } catch (InvalidFileNameProcessorException e) {
  23. return "Incorrect file name processor class '" + propertiesFileNameProcessor + "'";
  24. } finally {
  25. propertiesFileNameProcessorBuilder.destroy();
  26. }
  27. }

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

  1. public String getPropertiesFileNamePatternDescription() {
  2. ProjectDescriptor projectDescriptor = cloneProjectDescriptor(studio.getCurrentProjectDescriptor());
  3. projectDescriptor.setPropertiesFileNameProcessor(propertiesFileNameProcessor);
  4. PropertiesFileNameProcessor processor;
  5. PropertiesFileNameProcessorBuilder propertiesFileNameProcessorBuilder = new PropertiesFileNameProcessorBuilder();
  6. try {
  7. processor = propertiesFileNameProcessorBuilder.build(projectDescriptor);
  8. Class<? extends PropertiesFileNameProcessor> processorClass = processor.getClass();
  9. String fileName = "/" + processorClass.getName().replace(".", "/") + ".info";
  10. try {
  11. InputStream inputStream = processorClass.getResourceAsStream(fileName);
  12. if (inputStream == null) {
  13. throw new FileNotFoundException("File '" + fileName + "' is not found");
  14. }
  15. return IOUtils.toStringAndClose(inputStream);
  16. } catch (FileNotFoundException e) {
  17. return "Description file " + fileName + " is absent";
  18. } catch (IOException e) {
  19. log.error(e.getMessage(), e);
  20. return "Can't load the file " + fileName;
  21. }
  22. } catch (InvalidFileNameProcessorException e) {
  23. return "Incorrect file name processor class '" + propertiesFileNameProcessor + "'";
  24. } finally {
  25. propertiesFileNameProcessorBuilder.destroy();
  26. }
  27. }

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

  1. private RulesDeployGuiWrapper loadRulesDeploy(UserWorkspaceProject project) {
  2. try {
  3. AProjectResource artefact = (AProjectResource) project.getArtefact(RULES_DEPLOY_CONFIGURATION_FILE);
  4. InputStream content = artefact.getContent();
  5. String sourceString = IOUtils.toStringAndClose(content);
  6. return serializer.deserialize(sourceString, getSupportedVersion(project));
  7. } catch (IOException e) {
  8. FacesUtils.addErrorMessage("Cannot read " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
  9. log.error(e.getMessage(), e);
  10. } catch (ProjectException e) {
  11. FacesUtils.addErrorMessage("Cannot read " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
  12. log.error(e.getMessage(), e);
  13. } catch (XStreamException e) {
  14. FacesUtils.addErrorMessage("Cannot parse " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
  15. log.error(e.getMessage(), e);
  16. }
  17. return null;
  18. }

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

  1. private RulesDeployGuiWrapper loadRulesDeploy(UserWorkspaceProject project) {
  2. try {
  3. AProjectResource artefact = (AProjectResource) project.getArtefact(RULES_DEPLOY_CONFIGURATION_FILE);
  4. InputStream content = artefact.getContent();
  5. String sourceString = IOUtils.toStringAndClose(content);
  6. return serializer.deserialize(sourceString, getSupportedVersion(project));
  7. } catch (IOException e) {
  8. FacesUtils.addErrorMessage("Cannot read " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
  9. log.error(e.getMessage(), e);
  10. } catch (ProjectException e) {
  11. FacesUtils.addErrorMessage("Cannot read " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
  12. log.error(e.getMessage(), e);
  13. } catch (XStreamException e) {
  14. FacesUtils.addErrorMessage("Cannot parse " + RULES_DEPLOY_CONFIGURATION_FILE + " file");
  15. log.error(e.getMessage(), e);
  16. }
  17. return null;
  18. }

相关文章