List of usage examples for org.apache.commons.io IOUtils toString
public static String toString(byte[] input, String encoding) throws IOException
byte[]
as a String using the specified character encoding. From source file:com.rptools.io.FileParser.java
/** * Parses /data/[fileName] into an object T. * @param fileName The file to parse./*from ww w. j a v a 2 s . c om*/ * @return T Parsed contents of file. */ public T parseFile(String fileName) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream input = classLoader.getResourceAsStream("/data/" + fileName); try { String data = IOUtils.toString(input, "UTF-8"); return parseFileData(data); } catch (IOException e) { log.error(String.format(PARSE_ERROR, "/data/" + fileName), e); return null; } }
From source file:io.jmnarloch.cd.go.plugin.gradle.GradleTaskView.java
/** * {@inheritDoc}//from w w w. j a va 2 s . c o m */ @Override public String template() { try (InputStream inputStream = getClass().getResourceAsStream(TEMPLATE_PATH)) { return IOUtils.toString(inputStream, StandardCharsets.UTF_8); } catch (IOException e) { throw new PluginException("The view template could not be loaded.", e); } }
From source file:com.github.zdsiyan.maven.plugin.smartconfig.internal.RegexConfigurator.java
@Override public ByteArrayOutputStream execute(InputStream in, Charset charset, List<PointHandle> pointhandles) throws IOException { String text = IOUtils.toString(in, charset); Pattern pattern;/* w w w . java 2 s . co m*/ Matcher matcher; for (PointHandle point : pointhandles) { pattern = Pattern.compile(point.getExpression()); matcher = pattern.matcher(text); while (matcher.find()) { switch (point.getMode()) { case insert: break; case delete: break; case replace: default: text = matcher.replaceAll(point.getValue()); break; } } } ByteArrayOutputStream out = new ByteArrayOutputStream(); out.write(text.getBytes(charset)); return out; }
From source file:com.drisoftie.cwdroid.api.CwApiParser.java
public T parse() throws IOException { String xml = IOUtils.toString(new URL(builder.builder.toString()), CharEncoding.UTF_8); Serializer serializer = new Persister(); T root = null;/* w ww . j a v a2 s.c o m*/ try { root = (T) serializer.read(type, xml); } catch (Exception e) { e.printStackTrace(); } return root; }