Package net.jcores.jre

Examples of net.jcores.jre.CommonCore


     * @return The same core file object (<code>this</code>).
     */
    public CoreFile append(Object object, final Option... options) {
        if (object == null) return this;

        final CommonCore cc = this.commonCore;
        final String string = object.toString();

        map(new F1<File, Object>() {
            public Object f(File x) {
                try {
View Full Code Here


            this.commonCore.report(MessageType.MISUSE, "Destination null for copy().");
            return this;
        }

        final File dest = new File(destination);
        final CommonCore cc = this.commonCore;

        return new CoreFile(this.commonCore, map(new F1<File, File[]>() {
            @Override
            public File[] f(File x) {
                return Files.copy(cc, x, dest);
View Full Code Here

     * <br/>
     *
     * @return A CoreByteBuffer with binary content.
     */
    public CoreByteBuffer data() {
        final CommonCore cc = this.commonCore;
        return new CoreByteBuffer(this.commonCore, map(new F1<File, ByteBuffer>() {
            public ByteBuffer f(File x) {
                try {
                    final FileChannel channel = new FileInputStream(x).getChannel();
                    final long size = channel.size();

                    final ByteBuffer buffer = ByteBuffer.allocate((int) size);
                    int read = channel.read(buffer);

                    if (read != size) {
                        cc.report(MessageType.EXCEPTION, "Error reading data() from " + x + ". Size mismatch (" + read + " != " + size + ")");
                        return null;
                    }

                    channel.close();
                    return buffer;
                } catch (FileNotFoundException e) {
                    cc.report(MessageType.EXCEPTION, "Error reading data() from " + x + ". File not found!");
                    return null;
                } catch (IOException e) {
                    cc.report(MessageType.EXCEPTION, "Error reading data() from " + x + ". IOException!");
                    return null;
                }
            }
        }).array(ByteBuffer.class));
    }
View Full Code Here

     * <br/>
     *
     * @return The same core file object (<code>this</code>).
     */
    public CoreFile delete() {
        final CommonCore cc = this.commonCore;
        map(new F1<File, Void>() {
            public Void f(File x) {
                int lastSize = Integer.MAX_VALUE;
                List<File> list = CoreKeeper.$(x).dir(ListDirectories.DO).list();

                while (list.size() < lastSize) {
                    lastSize = list.size();

                    for (File file : list) {
                        file.delete();
                    }

                    list = CoreKeeper.$(x).dir(ListDirectories.DO).list();
                }

                // Try to delete the entry
                if (!x.delete()) {
                    cc.report(MessageType.EXCEPTION, "Unable to delete " + x);
                }

                return null;
            }
        });
View Full Code Here

     * <br/>
     *
     * @return A CoreBufferedImage with the loaded images.
     */
    public CoreBufferedImage image() {
        final CommonCore cc = this.commonCore;
        return new CoreBufferedImage(this.commonCore, map(new F1<File, BufferedImage>() {
            public BufferedImage f(File x) {
                try {
                    return ImageIO.read(x);
                } catch (IOException e) {
                    cc.report(MessageType.EXCEPTION, "Error loading image " + x);
                }
                return null;
            }
        }).array(BufferedImage.class));
    }
View Full Code Here

     * <br/>
     *
     * @return A CoreString object containing the files' contents.
     */
    public CoreString text() {
        final CommonCore cc = this.commonCore;
        return new CoreString(this.commonCore, map(new F1<File, String>() {
            public String f(final File x) {
                return Files.readText(cc, x);
            }
        }).array(String.class));
View Full Code Here

     * <br/>
     *
     * @return A CoreFile object enclosing the files of all downloaded URIs.
     */
    public CoreFile download() {
        final CommonCore cc = this.commonCore;

        return new CoreFile(this.commonCore, map(new F1<URI, File>() {
            public File f(URI x) {
                try {
                    final URL url = x.toURL();
                    final InputStream openStream = url.openStream();
                    final File file = File.createTempFile("jcores.download.", ".tmp");

                    Streams.saveTo(openStream, file);

                    openStream.close();

                    return file;
                } catch (MalformedURLException e) {
                    cc.report(MessageType.EXCEPTION, "URI " + x + " could not be transformed into an URL.");
                } catch (IOException e) {
                    cc.report(MessageType.EXCEPTION, "URI " + x + " could not be opened for reading.");
                }

                return null;
            }
        }).array(File.class));
View Full Code Here

     * @return A CoreFile object enclosing the files of all downloaded URIs.
     */
    public CoreFile download(final String path) {
        // Create output directory
        new File(path).mkdirs();
        final CommonCore cc = this.commonCore;

        return new CoreFile(this.commonCore, map(new F1<URI, File>() {
            public File f(URI x) {
                try {
                    final String filepath = CoreKeeper.$(x.getPath()).split("/").get(-1);
                    final URL url = x.toURL();
                    final InputStream openStream = url.openStream();
                    final File file = new File(path + "/" + filepath);

                    Streams.saveTo(openStream, file);

                    openStream.close();

                    return file;
                } catch (MalformedURLException e) {
                    cc.report(MessageType.EXCEPTION, "URI " + x + " could not be transformed into an URL.");
                } catch (IOException e) {
                    cc.report(MessageType.EXCEPTION, "URI " + x + " could not be opened for reading.");
                }

                return null;
            }
        }).array(File.class));
View Full Code Here

     * @param options Options to listen to.
     *
     * @return This object again.
     */
    public CoreJComponent onDrop(final F1<CoreObject<Object>, Void> handler, final Option... options) {
        final CommonCore cc = this.commonCore;

        for (int i = 0; i < size(); i++) {
            final JComponent component = (JComponent) get(i);
            if (component == null) continue;

View Full Code Here

TOP

Related Classes of net.jcores.jre.CommonCore

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.