本文整理汇总了Java中org.codehaus.plexus.util.IOUtil.toString方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtil.toString方法的具体用法?Java IOUtil.toString怎么用?Java IOUtil.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.plexus.util.IOUtil
的用法示例。
在下文中一共展示了IOUtil.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addJavaSource
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private void addJavaSource( Set<String> resources, JarOutputStream jos, String name, InputStream is,
List<Relocator> relocators, boolean consistentDates )
throws IOException
{
JarEntry jarEntry = new ConsistentJarEntry( name, consistentDates );
jos.putNextEntry( jarEntry );
String sourceContent = IOUtil.toString( new InputStreamReader( is, "UTF-8" ) );
for ( Relocator relocator : relocators )
{
sourceContent = relocator.applyToSourceContent( sourceContent );
}
final Writer writer = new OutputStreamWriter( jos, "UTF-8" );
IOUtil.copy( sourceContent, writer );
writer.flush();
resources.add( name );
}
示例2: testPluginPomWorksAndOutputsHtmlReportAndXmlReport
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
public void testPluginPomWorksAndOutputsHtmlReportAndXmlReport() throws Exception {
mojo = lookupMojoFromPom("xmlTestability.xml");
assertNotNull(mojo);
mojo.execute();
File outputDir = (File) getVariableValueFromObject(mojo, "outputDirectory");
String resultFile = (String) getVariableValueFromObject(mojo, "resultfile");
File targetDir = (File) getVariableValueFromObject(mojo, "targetDirectory");
File results = new File(outputDir, resultFile + ".html");
assertTrue("HTML report should exist: " + results.getAbsolutePath(), results.exists());
String content = IOUtil.toString(new FileReader(results));
assertTrue("HTML report content: " + content, content.contains("TestabilityExplorerMojo"));
results = new File(targetDir, resultFile + ".xml");
assertTrue("XML report should exist: " + results.getAbsolutePath(), results.exists());
content = IOUtil.toString(new FileReader(results));
assertTrue("XML report content: " + content, content.contains("TestabilityExplorerMojo"));
}
示例3: addJavaSource
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private void addJavaSource(Set<String> resources, JarOutputStream jos, String name, InputStream is,
List<Relocator> relocators)
throws IOException {
jos.putNextEntry(new JarEntry(name));
String sourceContent = IOUtil.toString(new InputStreamReader(is, "UTF-8"));
for (Relocator relocator : relocators) {
sourceContent = relocator.applyToSourceContent(sourceContent);
}
OutputStreamWriter writer = new OutputStreamWriter(jos, "UTF-8");
IOUtil.copy(sourceContent, writer);
writer.flush();
resources.add(name);
}
示例4: readServiceEntry
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private void readServiceEntry(String name, InputStream inputStream) throws IOException {
if (!isIncluded(name)) {
return;
}
String typeName = toClassFilePath(name.replace(SERVICES_ENTRY_PREFIX, ""));
if (typeName.isEmpty()) {
return;
}
boolean forcedInclusion = isSpecificallyIncluded(name);
if (forcedInclusion) {
included.add(typeName);
}
String content = IOUtil.toString(inputStream, Charsets.UTF_8.name());
for (String providerType : SERVICES_SPLITTER.split(content)) {
String providerName = toClassFilePath(providerType);
services.put(typeName, providerName);
if (forcedInclusion) {
included.add(providerName);
}
}
}
示例5: generate
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
@Override protected void generate() throws Exception {
File pd = new File(outputDirectory, packageName.replaceAll("\\.", "/"));
if (getLog().isDebugEnabled()) {
getLog().info("Creating directory " + pd);
}
pd.mkdirs();
InputStream in = null;
try {
in = ResourceMojo.class.getResourceAsStream(
"/net/hydromatic/resource/Resources.java");
String template = IOUtil.toString(in, "UTF-8");
template = template.replace("package net.hydromatic.resource;",
"package " + packageName + ";");
saveResult(new File(pd, "Resources.java"), template);
} finally {
if (in != null) {
in.close();
}
}
}
示例6: findCluster
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private String findCluster( JarFile jf )
throws MojoFailureException, IOException
{
ZipEntry entry = jf.getEntry( "Info/info.xml" );
InputStream ins = jf.getInputStream( entry );
String str = IOUtil.toString( ins, "UTF8" );
Matcher m = patt.matcher( str );
if ( !m.matches() )
{
getLog().info( "Cannot find cluster for " + jf.getName() + " Falling back to default value - '"
+ defaultCluster + "'." );
return defaultCluster;
}
else
{
return m.group( 1 );
}
}
示例7: loadAllFunctionTemplates
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
protected List<FunctionTemplate> loadAllFunctionTemplates() throws Exception {
info("");
info(LOAD_TEMPLATES);
try (final InputStream is = AddMojo.class.getResourceAsStream("/templates.json")) {
final String templatesJsonStr = IOUtil.toString(is);
final List<FunctionTemplate> templates = parseTemplateJson(templatesJsonStr);
info(LOAD_TEMPLATES_DONE);
return templates;
} catch (Exception e) {
error(LOAD_TEMPLATES_FAIL);
throw e;
}
}
示例8: getLatestVersion
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private String getLatestVersion() {
String url = "http://search.maven.org/solrsearch/select";
String param = "g:\"_groupid_\" AND a:\"_artifactid_\"";
param = param.replace("_groupid_", groupId).replace("_artifactid_", artifactId);
try {
List<NameValuePair> paramList = new ArrayList<>();
NameValuePair nvp1 = new BasicNameValuePair("q", param);
paramList.add(nvp1);
NameValuePair nvp2 = new BasicNameValuePair("wt", "json");
paramList.add(nvp2);
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
URI uri = new URIBuilder(request.getURI()).addParameters(paramList).build();
request.setURI(uri);
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() != 200) {
return "1.0.0";
}
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
String res = IOUtil.toString(is);
Gson gson = new GsonBuilder().create();
MavenResponse mavenResponse = gson.fromJson(res, MavenResponse.class);
if (mavenResponse.response.docs == null || mavenResponse.response.docs.isEmpty()) {
return "1.0.0";
}
return mavenResponse.response.docs.get(0).latestVersion;
} catch (Exception e) {
return "1.0.0";
}
}
示例9: loadTextResource
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private String loadTextResource(URL resource) throws IOException {
InputStream is = resource.openStream();
try {
return IOUtil.toString(is, "UTF-8");
} finally {
IOUtil.close(is);
}
}
示例10: getReference
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
private static String getReference(String artifactUrlReference) throws IOException {
URL referenceUrl = new URL(artifactUrlReference);
InputStream referenceUrlStream = referenceUrl.openStream();
String reference = IOUtil.toString(referenceUrlStream);
if(reference==null || reference.isEmpty() || reference.contains("\n")){
throw new IllegalArgumentException("artifactUrlReference resource should be non empty");
}
return reference;
}
示例11: readXmlFile
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
/**
* Reads a file into a String.
*
* @param outFile The file to read.
* @return String The content of the file.
* @throws java.io.IOException when things go wrong.
*/
public static StringBuilder readXmlFile( File outFile )
throws IOException
{
try( Reader reader = ReaderFactory.newXmlReader( outFile ) )
{
return new StringBuilder( IOUtil.toString( reader ) );
}
}
示例12: createCassandraYaml
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
/**
* Generates the {@code cassandra.yaml} file.
*
* @param cassandraYaml the {@code cassandra.yaml} file.
* @param data The data directory.
* @param commitlog The commitlog directory.
* @param savedCaches The saved caches directory.
* @param listenAddress The address to listen on for storage and other cassandra servers.
* @param rpcAddress The address to listen on for clients.
* @param seeds The seeds.
* @throws IOException If something went wrong.
*/
private void createCassandraYaml( File cassandraYaml, File data, File commitlog, File savedCaches,
String listenAddress, String rpcAddress, BigInteger initialToken, String[] seeds )
throws IOException
{
String defaults = IOUtil.toString( getClass().getResourceAsStream( "/cassandra.yaml" ) );
StringBuilder config = new StringBuilder();
config.append( "data_file_directories:\n" ).append( " - " ).append( data.getAbsolutePath() ).append( "\n" );
config.append( "commitlog_directory: " ).append( commitlog ).append( "\n" );
config.append( "saved_caches_directory: " ).append( savedCaches ).append( "\n" );
config.append( "initial_token: " ).append(
initialToken == null || "null".equals( initialToken ) ? "" : initialToken.toString() ).append( "\n" );
config.append( "listen_address: " ).append( listenAddress ).append( "\n" );
config.append( "storage_port: " ).append( storagePort ).append( "\n" );
config.append( "rpc_address: " ).append( rpcAddress ).append( "\n" );
config.append( "rpc_port: " ).append( rpcPort ).append( "\n" );
config.append( "native_transport_port: " ).append( nativeTransportPort ).append( "\n" );
config.append( "start_native_transport: " ).append( startNativeTransport ).append( "\n" );
if ( seeds != null )
{
config.append( "seed_provider: " ).append( "\n" );
config.append( " - class_name: org.apache.cassandra.locator.SimpleSeedProvider" ).append( "\n" );
config.append( " parameters:" ).append( "\n" );
String sep = " - seeds: \"";
for ( int i = 0; i < seeds.length; i++ )
{
config.append( sep ).append( seeds[i] );
sep = ", ";
}
if ( sep.length() == 2 )
{
config.append( "\"" ).append( "\n" );
}
}
FileUtils.fileWrite( cassandraYaml.getAbsolutePath(),
Utils.merge( Utils.merge( defaults, yaml ), config.toString() ) );
}
示例13: readXmlFile
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
/**
* Reads a file into a String.
*
* @param outFile The file to read.
* @return String The content of the file.
* @throws java.io.IOException when things go wrong.
*/
public static StringBuilder readXmlFile( File outFile )
throws IOException
{
Reader reader = ReaderFactory.newXmlReader( outFile );
try
{
return new StringBuilder( IOUtil.toString( reader ) );
}
finally
{
IOUtil.close( reader );
}
}
示例14: load
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
@Override
public Source load(final String sourceFile) throws IOException {
InputStream stream = locate(sourceFile);
if (stream != null) {
try (Md5DigestInputStream ds = new Md5DigestInputStream(stream);
InputStreamReader reader = new InputStreamReader(ds, getSourceEncoding())) {
String source = IOUtil.toString(reader);
return new Source(getFileName(sourceFile), source, ds.getDigestHex());
} catch (NoSuchAlgorithmException ex) {
throw new IOException("MD5 algorithm not available", ex);
}
} else {
return null;
}
}
示例15: readFileContent
import org.codehaus.plexus.util.IOUtil; //导入方法依赖的package包/类
public static String readFileContent(final File file) throws IOException {
InputStreamReader reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
try {
return IOUtil.toString(reader);
} finally {
IOUtil.close(reader);
}
}