本文整理了Java中org.apache.wicket.util.io.IOUtils.toString()
方法的一些代码示例,展示了IOUtils.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.toString()
方法的具体详情如下:
包路径:org.apache.wicket.util.io.IOUtils
类名称:IOUtils
方法名:toString
[英]Get the contents of an InputStream
as a String using the default character encoding of the platform.
This method buffers the input internally, so there is no need to use a BufferedInputStream
.
[中]使用平台的默认字符编码以字符串形式获取InputStream
的内容。
此方法在内部缓冲输入,因此无需使用BufferedInputStream
。
代码示例来源:origin: org.wicketstuff/wicketstuff-console-templates
static String readFile(final File file)
{
try
{
final BufferedInputStream bin = new BufferedInputStream(new FileInputStream(file));
try
{
return IOUtils.toString(bin);
}
finally
{
bin.close();
}
}
catch (final IOException e)
{
throw new RuntimeException("Could not read file " + file, e);
}
}
代码示例来源:origin: org.jbehave.web/jbehave-web-runner
protected void outputAs(String id, String ext) {
String url = url(id, ext);
File file = new File(StringUtils.substringAfter(url, "file:"));
String content;
try {
content = IOUtils.toString(new FileInputStream(file));
} catch (IOException e) {
content = e.getMessage();
}
MultiLineLabel output = (MultiLineLabel) get("output");
output.setDefaultModelObject(content);
}
代码示例来源:origin: apache/syncope
public void load() {
mimeTypesMap = new HashMap<>();
try {
JsonNode jsonNode = MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream("/MIMETypes.json")));
for (JsonNode node : jsonNode) {
JsonNode type = node.path("name");
JsonNode ext = node.path("extension");
if (!type.isMissingNode()) {
mimeTypesMap.put(type.asText(), ext.isMissingNode() ? "" : ext.asText());
}
}
mimeTypesMap = Collections.unmodifiableMap(mimeTypesMap);
LOG.debug("MIME types loaded: {}", mimeTypesMap);
mimeTypes = new ArrayList<>(mimeTypesMap.keySet());
Collections.sort(mimeTypes);
mimeTypes = Collections.unmodifiableList(mimeTypes);
} catch (Exception e) {
LOG.error("Error reading file MIMETypes from resources", e);
}
}
代码示例来源:origin: jbehave/jbehave-web
protected void outputAs(String id, String ext) {
String url = url(id, ext);
File file = new File(StringUtils.substringAfter(url, "file:"));
String content;
try {
content = IOUtils.toString(new FileInputStream(file));
} catch (IOException e) {
content = e.getMessage();
}
MultiLineLabel output = (MultiLineLabel) get("output");
output.setDefaultModelObject(content);
}
代码示例来源:origin: org.onehippo.cms7/hippo-cms-api
public static String svgAsString(PackageResourceReference reference, String... cssClasses) throws ResourceStreamNotFoundException, IOException {
final PackageResource resource = reference.getResource();
final IResourceStream resourceStream = resource.getResourceStream();
if (resourceStream == null) {
throw new ResourceStreamNotFoundException("Cannot find SVG icon " + resource);
}
String svgAsString = IOUtils.toString(resourceStream.getInputStream());
int rootIndex = svgAsString.indexOf("<svg");
if (rootIndex == -1) {
throw new IllegalArgumentException("Cannot find SVG root element in " + resource);
}
//skip everything (comments, xml declaration and dtd definition) before <svg element
svgAsString = svgAsString.substring(rootIndex);
//append css classes if present
final String cssClassesAsString = cssClassesAsString(cssClasses);
if (StringUtils.isNotEmpty(cssClassesAsString)) {
//check if class attribute is present and part of <svg element
final int classAttributeIndex = svgAsString.indexOf("class=\"");
if (classAttributeIndex > -1 && classAttributeIndex < svgAsString.indexOf(">")) {
int insertCssClassesAt = classAttributeIndex + 7;
svgAsString = svgAsString.substring(0, insertCssClassesAt) + cssClassesAsString + " " +
svgAsString.substring(insertCssClassesAt);
} else {
svgAsString = "<svg class=\"" + cssClassesAsString + "\"" + svgAsString.substring(4);
}
}
return svgAsString;
}
代码示例来源:origin: org.wicketstuff/wicketstuff-gmap2
/**
* @param address
* @return
* @throws IOException
*/
public GLatLng geocode(final String address) throws IOException
{
InputStream is = invokeService(encode(address));
if (is != null)
{
try
{
String content = org.apache.wicket.util.io.IOUtils.toString(is);
return decode(content);
}
finally
{
is.close();
}
}
return null;
}
代码示例来源:origin: org.wicketstuff/browserid
outputStream.close();
String response = IOUtils.toString(urlConnection.getInputStream(), "UTF-8");
代码示例来源:origin: org.wicketstuff/wicketstuff-gmap3
/**
* Invoke a geocoder request to the GoogleMaps API.<br/>
* Only return the first element of {@link #geocoderResult} to be backward compatible.<br/>
* After successful call of {@link #geocode(String)} you can get all results from
* {@link #geocoderResult}
*
* @param address
* - Requested address
* @return {@link GLatLng} - only first hit of the request
* @throws IOException
*/
public GLatLng geocode(final String address) throws IOException
{
InputStream is = invokeService(encode(address));
if (is != null)
{
try
{
String content = org.apache.wicket.util.io.IOUtils.toString(is);
return decode(content);
}
finally
{
is.close();
}
}
return null;
}
代码示例来源:origin: de.agilecoders.wicket/bootstrap-extensions
@BeforeClass
public static void before() throws IOException {
content = IOUtils.toString(YuiCssCompressorTest.class.getResourceAsStream("test.css"));
compressor = new YuiCssCompressor();
}
代码示例来源:origin: OrienteerBAP/Orienteer
String content = IOUtils.toString(httpRequest.getInputStream());
ODocument log = OLoggerModule.storeOLoggerEvent(content);
out = log.toJSON();
代码示例来源:origin: org.apache.syncope.client/syncope-client-enduser
IOUtils.toString(request.getInputStream()), Credentials.class);
final String username = credentials.getUsername();
final String password = credentials.getPassword().isEmpty() ? null : credentials.getPassword();
代码示例来源:origin: de.agilecoders.wicket/bootstrap
@Override
protected void onBefore() {
try {
cssContent = IOUtils.toString(BootstrapCssReference.INSTANCE.getResource().getResourceStream().getInputStream());
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ResourceStreamNotFoundException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: de.agilecoders.wicket/bootstrap-extensions
/**
* compiles a given less file
*
* @param fileName The file name (relative to this class)
* @return compiled content
*/
private String compileLessFile(final String fileName) {
final String content;
try {
content = IOUtils.toString(Less4JCompilerTest.class.getResourceAsStream("responsive.less"));
} catch (IOException e) {
throw new WicketRuntimeException(e);
}
return compile(content);
}
代码示例来源:origin: de.agilecoders.wicket/bootstrap
@Override
public String asText() {
InputStream stream = null;
try {
stream = getInputStream();
return IOUtils.toString(stream,
Bootstrap.getSettings(Application.get()).getBootstrapLessCompilerSettings().getCharset().name());
} catch (IOException e) {
throw new WicketRuntimeException(e);
} finally {
IOUtils.closeQuietly(stream);
}
}
代码示例来源:origin: apache/syncope
@Override
public Component preview(final byte[] uploadedBytes) {
Fragment fragment = new Fragment("preview", "noPreviewFragment", this);
if (uploadedBytes.length > 0) {
try {
fragment = new Fragment("preview", "previewFragment", this);
InputStream stream = new ByteArrayInputStream(uploadedBytes);
TextArea<String> jsonEditor =
new TextArea<>("jsonEditorInfo", new Model<>(IOUtils.toString(stream)));
jsonEditor.setOutputMarkupPlaceholderTag(true);
jsonEditorInfoId = jsonEditor.getMarkupId();
fragment.add(jsonEditor);
} catch (IOException e) {
LOG.error("Error evaluating text file", e);
}
}
WebMarkupContainer previewContainer = new WebMarkupContainer("previewContainer");
previewContainer.setOutputMarkupId(true);
previewContainer.add(fragment);
return this.addOrReplace(previewContainer);
}
代码示例来源:origin: l0rdn1kk0n/wicket-webjars
@Test
public void findOnGAE() throws ResourceStreamNotFoundException, IOException {
System.setProperty("com.google.appengine.runtime.environment", "Production");
WebjarsResourceFinder finder = new WebjarsResourceFinder(WicketWebjars.settings());
IResourceStream stream = finder.find(IWebjarsResourceReference.class, "/webjars/jquery/2.2.1/jquery.min.js");
System.setProperty("com.google.appengine.runtime.environment", "");
assertThat(stream, is(not(nullValue())));
assertThat(IOUtils.toString(stream.getInputStream()), startsWith("/*! jQuery v2.2.1"));
}
代码示例来源:origin: l0rdn1kk0n/wicket-webjars
@Test
public void findFile() throws ResourceStreamNotFoundException, IOException {
WebjarsResourceFinder finder = new WebjarsResourceFinder(WicketWebjars.settings());
IResourceStream stream = finder.find(IWebjarsResourceReference.class, "/webjars/jquery/2.2.1/jquery.min.js");
assertThat(stream, is(not(nullValue())));
assertThat(IOUtils.toString(stream.getInputStream()), startsWith("/*! jQuery v2.2.1"));
}
代码示例来源:origin: de.agilecoders.wicket/bootstrap-extensions
/**
* compiles given content with {@link Less4JCompiler}
*
* @param content to compile
* @return compiled content as string
*/
private String compile(final String content) {
try {
return removeLineBreaks(IOUtils.toString(compiler.compile(on(content)).getInputStream(), Charsets.UTF_8.toString()));
} catch (Exception e) {
if (e instanceof Less4jException) {
return new Less4JCompiler.ErrorLogger("test", (Less4jException) e).toString();
}
throw new RuntimeException(e);
}
}
代码示例来源:origin: de.agilecoders.wicket/bootstrap
@Override
protected void onBefore() {
try {
cssContent = IOUtils.toString(BootswatchCssReference.CERULEAN.getResource().getResourceStream().getInputStream());
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ResourceStreamNotFoundException e) {
throw new RuntimeException(e);
}
getBootstrapSettings().getBootstrapLessCompilerSettings()
.setCacheStrategy(IBootstrapLessCompilerSettings.CacheStrategy.Never)
.setUseLessCompiler(true);
}
代码示例来源:origin: l0rdn1kk0n/wicket-webjars
@Test
public void findFileWithoutVersion() throws ResourceStreamNotFoundException, IOException {
WebjarsResourceFinder finder = new WebjarsResourceFinder(WicketWebjars.settings());
IResourceStream stream = finder.find(IWebjarsResourceReference.class,
useRecent("/webjars/jquery/current/jquery.min.js"));
assertThat(stream, is(not(nullValue())));
assertThat(IOUtils.toString(stream.getInputStream()), startsWith("/*! jQuery v2.2.1"));
}
内容来源于网络,如有侵权,请联系作者删除!