当前位置: 首页>>代码示例>>Java>>正文


Java IOUtils类代码示例

本文整理汇总了Java中org.jboss.gravia.utils.IOUtils的典型用法代码示例。如果您正苦于以下问题:Java IOUtils类的具体用法?Java IOUtils怎么用?Java IOUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IOUtils类属于org.jboss.gravia.utils包,在下文中一共展示了IOUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIncrementForPrefix

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
@SuppressWarnings("resource")
private int getIncrementForPrefix(String prefix) {
    String path = String.format(COUNTER_PATH, prefix);
    SharedCount sharedCount = new SharedCount(curator.get(), path, 1);
    try {
        sharedCount.start();
        for (int count = sharedCount.getCount(); true; count = sharedCount.getCount()) {
            if (sharedCount.trySetCount(count + 1)) {
                return count;
            }
        }
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    } finally {
        IOUtils.safeClose(sharedCount);
    }
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:18,代码来源:ClusterDataStoreImpl.java

示例2: getProfileVersion

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
LinkedProfileVersion getProfileVersion(VersionIdentity version) {

            // git reset --hard
            resetHard();

            // git checkout [version]
            checkoutBranch(version.getVersion(), false);

            ProfileVersionBuilder builder = new DefaultProfileVersionBuilder(version);
            FileInputStream fis = null;
            try {
                File metadataFile = workspace.resolve(PROFILES_METADATA_FILE).toFile();
                fis = new FileInputStream(metadataFile);
                DefaultProfileXMLReader reader = new DefaultProfileXMLReader(fis);
                Profile profile = reader.nextProfile();
                while (profile != null) {
                    builder.addProfile(profile);
                    profile = reader.nextProfile();
                }
            } catch (IOException ex) {
                throw new IllegalStateException("Cannot profile version: " + version, ex);
            } finally {
                IOUtils.safeClose(fis);
            }

            return builder.getProfileVersion();
        }
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:28,代码来源:ProfileRegistry.java

示例3: writeProfileVersion

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
void writeProfileVersion(LinkedProfileVersion profileVersion, String message) {

            // git reset --hard
            resetHard();

            // git checkout -b [version]
            Version version = profileVersion.getIdentity().getVersion();
            checkoutBranch(version, true);

            FileOutputStream fos = null;
            try {
                File metadataFile = workspace.resolve(PROFILES_METADATA_FILE).toFile();
                fos = new FileOutputStream(metadataFile);
                ContentHandler contentHandler = new ResourceItemContentHandler(workspace);
                DefaultProfileXMLWriter writer = new DefaultProfileXMLWriter(fos, contentHandler);
                writer.writeProfileVersion(profileVersion);
                writer.close();
            } catch (IOException ex) {
                throw new IllegalStateException("Cannot add profile version: " + profileVersion, ex);
            } finally {
                IOUtils.safeClose(fos);
            }

            // git add --all
            addAll();

            // git commit
            commit(message);
        }
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:30,代码来源:ProfileRegistry.java

示例4: testURLHandlerService

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
@Test
public void testURLHandlerService() throws Exception {

    try {
        new URL("foo://hi");
        Assert.fail("No handler registered. Should throw a MalformedURLException.");
    } catch (MalformedURLException mue) {
        // expected
    }

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    ModuleContext syscontext = runtime.getModuleContext();

    Dictionary<String, Object> props = new Hashtable<>();
    props.put(Constants.URL_HANDLER_PROTOCOL, "foo");
    ServiceRegistration<URLStreamHandler> sreg = syscontext.registerService(URLStreamHandler.class, new MyHandler(), props);

    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copyStream(new URL("foo://somehost").openStream(), baos);
        Assert.assertEquals("somehost", new String(baos.toByteArray()));

        URL url = new URL("foo:///somepath");
        Assert.assertEquals("", url.getHost());
    } finally {
        sreg.unregister();
    }

    try {
        new URL("foo://hi").openConnection();
        Assert.fail("No handler registered any more.");
    } catch (IOException ex) {
        // expected
    }
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:36,代码来源:URLStreamHandlerTestBase.java

示例5: transformCatalinaProperties

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
private void transformCatalinaProperties(MutableManagedProcess process, File configFile) throws Exception {
    IllegalStateAssertion.assertTrue(configFile.exists(), "File does not exist: " + configFile);

    FileInputStream instream = new FileInputStream(configFile);
    Properties properties = new Properties();
    properties.load(instream);
    IOUtils.safeClose(instream);

    FileOutputStream outstream = new FileOutputStream(configFile);
    properties.setProperty("runtime.id", process.getIdentity().getName());
    properties.store(outstream, "Managed container properties");
    IOUtils.safeClose(outstream);
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:14,代码来源:TomcatProcessHandler.java

示例6: createDeployment

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
@Deployment
public static JavaArchive createDeployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-jcr-tests.jar");
    archive.addAsResource("jcr/repository-simple-security.xml");
    archive.addClasses(FileUtils.class, IOUtils.class);
    archive.setManifest(() -> {
        ManifestBuilder builder = new ManifestBuilder();
        builder.addManifestHeader("Dependencies", "org.apache.jackrabbit");
        return builder.openStream();
    });
    return archive;
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:13,代码来源:JcrIntegrationTest.java

示例7: before

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
@Before
public void before() throws Exception {
    FileUtils.deleteDirectory(REPO_PATH);
    REPO_PATH.toFile().mkdirs();

    File configFile = REPO_PATH.resolve("repository-simple-security.xml").toFile();
    InputStream input = getClass().getClassLoader().getResourceAsStream("jcr/repository-simple-security.xml");
    try (OutputStream output = new FileOutputStream(configFile)) {
        IOUtils.copyStream(input, output);
    }

    repository = new TransientRepository(configFile, REPO_PATH.toFile());
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:14,代码来源:JcrIntegrationTest.java

示例8: createDeployment

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
@Deployment
public static JavaArchive createDeployment() {
    JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-asn1-tests.jar");
    archive.addAsResource("asn1/SMS_SINGLE.tt");
    archive.addClasses(IOUtils.class);
    return archive;
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:8,代码来源:ASN1DataFormatIntegrationTest.java

示例9: getByteArrayPayload

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
public byte[] getByteArrayPayload(String resName) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (InputStream ins = getClass().getClassLoader().getResourceAsStream(resName)) {
        IOUtils.copyStream(ins, baos);
    }
    return baos.toByteArray();
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:8,代码来源:ASN1DataFormatIntegrationTest.java

示例10: getResourceValue

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
public static String getResourceValue (Class<?> clazz, String resname) throws IOException {
    try (InputStream in = clazz.getResourceAsStream(resname)) {
        IllegalStateAssertion.assertNotNull(in, "Cannot find resource: " + resname);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copyStream(in, out);
        return new String(out.toByteArray());
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:9,代码来源:TestUtils.java

示例11: initDefaultContent

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
public RuntimeEnvironment initDefaultContent(InputStream content) {
    IllegalArgumentAssertion.assertNotNull(content, "content");
    try {
        RepositoryReader reader = new DefaultRepositoryXMLReader(content);
        Resource xmlres = reader.nextResource();
        while (xmlres != null) {
            systemStore.addResource(xmlres);
            xmlres = reader.nextResource();
        }
    } finally {
        IOUtils.safeClose(content);
    }
    return this;
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:15,代码来源:RuntimeEnvironment.java

示例12: testURLHandlerService

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
@Test
public void testURLHandlerService() throws Exception {

    try {
        new URL("foo://hi");
        Assert.fail("No handler registered. Should throw a MalformedURLException.");
    } catch (MalformedURLException mue) {
        // expected
    }

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    ModuleContext syscontext = runtime.getModuleContext();

    Dictionary<String, Object> props = new Hashtable<>();
    props.put(Constants.URL_HANDLER_PROTOCOL, "foo");
    ServiceRegistration<URLStreamHandler> sreg = syscontext.registerService(URLStreamHandler.class, new MyHandler(), props);

    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copyStream(new URL("foo://somehost").openStream(), baos);
        Assert.assertEquals("somehost", new String(baos.toByteArray()));
    } finally {
        sreg.unregister();
    }

    try {
        new URL("foo://hi").openConnection();
        Assert.fail("No handler registered any more.");
    } catch (IOException ex) {
        // expected
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:33,代码来源:URLStreamHandlerTest.java

示例13: PropertiesHeadersProvider

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
public PropertiesHeadersProvider(File file) throws IOException {
    IllegalArgumentAssertion.assertNotNull(file, "file");
    InputStream input = new FileInputStream(file);
    try {
        Properties props = new Properties();
        props.load(input);
        headers = fromProperties(props);
    } finally {
        IOUtils.safeClose(input);
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:12,代码来源:PropertiesHeadersProvider.java

示例14: doStop

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
@Override
protected void doStop(MutableManagedProcess process) throws Exception {

    String magicWord = "SHUTDOWN";

    // Try for 5sec to connect to send the SHUTDOWN command
    InetAddress addr = Inet4Address.getLocalHost();
    long now = System.currentTimeMillis();
    long end = now + 5000L;
    Socket socket = null;
    OutputStream output = null;
    while (socket == null && now < end) {
        try {
            socket = new Socket(addr, shutdownPort);
            output = socket.getOutputStream();
            output.write(magicWord.getBytes());
            output.flush();
        } catch (IOException ex) {
            Thread.sleep(500);
            now = System.currentTimeMillis();
        } finally {
            IOUtils.safeClose(output);
            IOUtils.safeClose(socket);
        }
    }

    /*
    List<String> cmd = new ArrayList<String>();
    cmd.add("java");

    File catalinaHome = process.getHomePath().toFile();
    String absolutePath = catalinaHome.getAbsolutePath();
    String CLASS_PATH = absolutePath + "/bin/bootstrap.jar" + File.pathSeparator;
    CLASS_PATH += absolutePath + "/bin/tomcat-juli.jar";

    cmd.add("-classpath");
    cmd.add(CLASS_PATH);
    cmd.add("-Djava.endorsed.dirs=" + absolutePath + "/endorsed");
    cmd.add("-Dcatalina.base=" + absolutePath);
    cmd.add("-Dcatalina.home=" + absolutePath);
    cmd.add("-Djava.io.tmpdir=" + absolutePath + "/temp");
    cmd.add("org.apache.catalina.startup.Bootstrap");
    cmd.add("stop");

    // execute command
    ProcessBuilder processBuilder = new ProcessBuilder(cmd);
    processBuilder.redirectErrorStream(true);
    processBuilder.directory(new File(catalinaHome, "bin"));
    Process shutdownProcess = processBuilder.start();

    ProcessOptions options = process.getCreateOptions();
    new Thread(new ConsoleConsumer(shutdownProcess, options)).start();
    shutdownProcess.waitFor();
    */
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:56,代码来源:TomcatProcessHandler.java

示例15: readCustomerXml

import org.jboss.gravia.utils.IOUtils; //导入依赖的package包/类
private String readCustomerXml(String xmlpath) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copyStream(getClass().getResourceAsStream(xmlpath), out);
    return new String(out.toByteArray());
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:6,代码来源:XSLTTransformTest.java


注:本文中的org.jboss.gravia.utils.IOUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。