/** * Opens a {@link Reader} that loads XML. * This method uses {@link #sniffEncoding() the right encoding}, * not just the system default encoding. * @throws IOException Encoding issues * @return Reader for the file. should be close externally once read. */ public Reader readRaw() throws IOException { try { InputStream fileInputStream = Files.newInputStream(file.toPath()); try { return new InputStreamReader(fileInputStream, sniffEncoding()); } catch (IOException ex) { // Exception may happen if we fail to find encoding or if this encoding is unsupported. // In such case we close the underlying stream and rethrow. Util.closeAndLogFailures(fileInputStream, LOGGER, "FileInputStream", file.toString()); throw ex; } } catch (InvalidPathException e) { throw new IOException(e); } }
/** * Writes {@code config.xml} to the specified output stream. * The user must have at least {@link #EXTENDED_READ}. * If he lacks {@link #CONFIGURE}, then any {@link Secret}s detected will be masked out. */ @Restricted(NoExternalUse.class) public void writeConfigDotXml(OutputStream os) throws IOException { checkPermission(EXTENDED_READ); XmlFile configFile = getConfigFile(); if (hasPermission(CONFIGURE)) { IOUtils.copy(configFile.getFile(), os); } else { String encoding = configFile.sniffEncoding(); String xml = FileUtils.readFileToString(configFile.getFile(), encoding); Matcher matcher = SECRET_PATTERN.matcher(xml); StringBuffer cleanXml = new StringBuffer(); while (matcher.find()) { if (Secret.decrypt(matcher.group(1)) != null) { matcher.appendReplacement(cleanXml, ">********<"); } } matcher.appendTail(cleanXml); org.apache.commons.io.IOUtils.write(cleanXml.toString(), os, encoding); } }
/** * Opens a {@link Reader} that loads XML. * This method uses {@link #sniffEncoding() the right encoding}, * not just the system default encoding. * @deprecated Should not be loading XML content using a character stream. */ @Deprecated public Reader readRaw() throws IOException { return new InputStreamReader(new FileInputStream(file),sniffEncoding()); }
/** * Opens a {@link Reader} that loads XML. * This method uses {@link #sniffEncoding() the right encoding}, * not just the system default encoding. * @deprecated Should not be loading XML content using a character stream. */ @Deprecated public Reader readRaw() throws IOException { return new InputStreamReader(new FileInputStream(file),sniffEncoding()); }
/** * Opens a {@link Reader} that loads XML. This method uses * {@link #sniffEncoding() the right encoding}, not just the system default * encoding. * * @deprecated Should not be loading XML content using a character stream. */ @Deprecated public Reader readRaw() throws IOException { return new InputStreamReader(new FileInputStream(file), sniffEncoding()); }
/** * Opens a {@link Reader} that loads XML. * This method uses {@link #sniffEncoding() the right encoding}, * not just the system default encoding. * @deprecated Should not be loading XML content using a character stream. */ @Deprecated public Reader readRaw() throws IOException { return new InputStreamReader(new FileInputStream(file),sniffEncoding()); }
/** * Opens a {@link Reader} that loads XML. * This method uses {@link #sniffEncoding() the right encoding}, * not just the system default encoding. * @throws IOException Encoding issues * @return Reader for the file. should be close externally once read. */ public Reader readRaw() throws IOException { try { InputStream fileInputStream = Files.newInputStream(file.toPath()); try { return new InputStreamReader(fileInputStream, sniffEncoding()); } catch (IOException ex) { // Exception may happen if we fail to find encoding or if this encoding is unsupported. // In such case we close the underlying stream and rethrow. Util.closeAndLogFailures(fileInputStream, LOGGER, "FileInputStream", file.toString()); throw ex; } } catch (InvalidPathException e) { throw new IOException(e); } }
/** * Writes {@code config.xml} to the specified output stream. * The user must have at least {@link #EXTENDED_READ}. * If he lacks {@link #CONFIGURE}, then any {@link Secret}s detected will be masked out. */ @Restricted(NoExternalUse.class) public void writeConfigDotXml(OutputStream os) throws IOException { checkPermission(EXTENDED_READ); XmlFile configFile = getConfigFile(); if (hasPermission(CONFIGURE)) { IOUtils.copy(configFile.getFile(), os); } else { String encoding = configFile.sniffEncoding(); String xml = FileUtils.readFileToString(configFile.getFile(), encoding); Matcher matcher = SECRET_PATTERN.matcher(xml); StringBuffer cleanXml = new StringBuffer(); while (matcher.find()) { if (Secret.decrypt(matcher.group(1)) != null) { matcher.appendReplacement(cleanXml, ">********<"); } } matcher.appendTail(cleanXml); org.apache.commons.io.IOUtils.write(cleanXml.toString(), os, encoding); } }