Package org.tools.io

Examples of org.tools.io.Resource


        // convert to xml
        Node root = p.toXML();

        // write to file
        Resource location = ResourceUtils.asResource("XMLTest.Property.xml");
        try (OutputStream out = location.getOutputStream()) {
            XMLHelper.write(out, root);
        }
        try (InputStream in = location.getInputStream()) {
            root = XMLHelper.read(in);
        }
        p.fromXML(root);

        // some tests
        Assert.assertTrue(p.size() == 4);
        Assert.assertTrue("mercedes".equals(p.get("car")));
        Assert.assertTrue("cat".equals(p.get("pet")));
        Assert.assertTrue(p.getInt("age") == 21);
        Assert.assertTrue(p.getBoolean("single") == true);

        // TODO this fails, something is not closed correctly

        // delete file again
        Assert.assertTrue(location.delete());

    }
View Full Code Here


        String key = getPath(place, location);
        if (imageCache.containsKey(key)) {
            return imageCache.get(key);
        }

        Resource resource = getAsResource(place, location);
        statistics.add(resource.getPath());
        BufferedImage image = null;
        try {
            image = ImageIO.read(resource.getInputStream());
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, resource.getPath(), ex);
        }

        // put in cache
        imageCache.put(key, image);
View Full Code Here

     * @param location
     * @return
     */
    public static InputStream getAsInputStream(Places place, String location) {
        try {
            Resource resource = getAsResource(place, location);
            if (resource != null) {
                return resource.getInputStream();
            }
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
        return null;
View Full Code Here

        }

        // one engineer unit in all nation's capitals

        try {
            Resource resource = new FileResource(exportFile);
            XMLHelper.write(resource, scenario);
        } catch (IOException ex) {
            updateStatus("could not write to scenario file");
            return;
        }
View Full Code Here

    private void saveButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed

        String out = baseTextField.getText() + "import.settings.xml";

        Resource resource;
        try {
            resource = ResourceUtils.asResource(out);
        } catch (IOException ex) {
            updateStatus("Cannot open save location.");
            return;
View Full Code Here

    private void loadButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_loadButtonActionPerformed

        String in = baseTextField.getText() + "import.settings.xml";

        Resource resource;
        try {
            resource = ResourceUtils.asResource(in);
        } catch (IOException ex) {
            updateStatus("Cannot open load location.");
            return;
View Full Code Here

        // music
        options.put(Option.Music_Mute.toString(), "false");
        // general
        options.put(Option.General_Version.toString(), "0.1.4 (demo)");

        Resource resource = ResourceUtils.asResource("options.default.xml");
        XMLHelper.write(resource, options);
    }
View Full Code Here

     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        Node parent = new Node("Music");
        parent.appendChild(makeBackgroundMusicList());
        Resource resource = ResourceUtils.asResource("music.xml");
        XMLHelper.write(resource, parent);
    }
View Full Code Here

        Node parent = new Node("Settings");
        parent.appendChild(createTerrainSettings());
        parent.appendChild(createResourceSettings());

        Resource resource = ResourceUtils.asResource("settings.xml");
        XMLHelper.write(resource, parent);
    }
View Full Code Here

     * then loads them all and puts the scenario titles in a list.
     */
    public void doScan() {
        scenarios.clear();

        Resource directory;
        try {
            directory = ResourceUtils.asResource(IOManager.getPath(Places.Scenarios, ""));
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, null, ex);
            return;
        }

        List<Resource> files;
        try {
            files = directory.list("scenario\\.[a-zA-z0-9]+\\.xml");
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, null, ex);
            return;
        }

View Full Code Here

TOP

Related Classes of org.tools.io.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.