Search in sources :

Example 1 with InputStream

use of com.xenoage.utils.io.InputStream in project Zong by Xenoage.

the class AndroidPlatformUtils method openFileAsync.

@Override
public void openFileAsync(String filePath, AsyncResult<InputStream> result) {
    try {
        InputStream stream = openFile(filePath);
        result.onSuccess(stream);
    } catch (IOException ex) {
        result.onFailure(ex);
    }
}
Also used : InputStream(com.xenoage.utils.io.InputStream) JseInputStream(com.xenoage.utils.jse.io.JseInputStream) IOException(java.io.IOException)

Example 2 with InputStream

use of com.xenoage.utils.io.InputStream in project Zong by Xenoage.

the class OpusLinkResolver method processNextItem.

/**
 * Processes the next opus item in the input queue, or finishes the processing
 * if the queue is empty.
 */
private void processNextItem() {
    if (input.size() > 0) {
        // another item to resolve
        OpusItem inputItem = input.remove(0);
        if (inputItem instanceof OpusLink) {
            // opus link; must be resolved
            String filePath = ((OpusLink) inputItem).getLink().getHref();
            if (zip != null) {
                // read zipped opus file
                InputStream opusStream;
                try {
                    opusStream = zip.openFile(filePath);
                    resolveItem(opusStream);
                } catch (com.xenoage.utils.io.FileNotFoundException ex) {
                    callback.onFailure(ex);
                }
            } else if (basePath != null) {
                // read plain opus file
                platformUtils().openFileAsync(basePath + "/" + filePath, new AsyncResult<InputStream>() {

                    @Override
                    public void onSuccess(InputStream opusStream) {
                        resolveItem(opusStream);
                    }

                    @Override
                    public void onFailure(Exception ex) {
                        callback.onFailure(ex);
                    }
                });
            } else {
                callback.onFailure(new IOException("neither zip nor basePath is given"));
            }
        } else if (inputItem instanceof Opus) {
            // opus; can contain links which must be resolved
            Opus childOpus = (Opus) inputItem;
            new OpusLinkResolver(childOpus, zip, basePath).produce(new AsyncResult<Opus>() {

                @Override
                public void onSuccess(Opus opus) {
                    acc.add(opus);
                    // item finished, next one
                    processNextItem();
                }

                @Override
                public void onFailure(Exception ex) {
                    callback.onFailure(ex);
                }
            });
        } else {
            // simple case. item needs not to be resolved, just add it
            acc.add(inputItem);
            processNextItem();
        }
    } else {
        // all items resolved
        callback.onSuccess(new Opus(opus.getTitle(), acc));
    }
}
Also used : InputStream(com.xenoage.utils.io.InputStream) OpusItem(com.xenoage.zong.io.musicxml.opus.OpusItem) Opus(com.xenoage.zong.io.musicxml.opus.Opus) IOException(java.io.IOException) AsyncResult(com.xenoage.utils.async.AsyncResult) IOException(java.io.IOException) OpusLink(com.xenoage.zong.io.musicxml.opus.OpusLink)

Example 3 with InputStream

use of com.xenoage.utils.io.InputStream in project Zong by Xenoage.

the class App method load.

/**
 * Loads the {@link ScoreDoc} with the given filename.
 */
public static ScoreDoc load(String filename) throws IOException {
    String filepath = "files/" + filename;
    InputStream in = io().openFile(filepath);
    try {
        return sync(new MusicXmlScoreDocFileReader(in, filepath).read());
    } catch (Exception ex) {
        throw new IOException(ex);
    }
}
Also used : InputStream(com.xenoage.utils.io.InputStream) MusicXmlScoreDocFileReader(com.xenoage.zong.io.musicxml.in.MusicXmlScoreDocFileReader) IOException(java.io.IOException) IOException(java.io.IOException)

Example 4 with InputStream

use of com.xenoage.utils.io.InputStream in project Zong by Xenoage.

the class AndroidPlatformUtils method openFileAsync.

@Override
public Promise<InputStream> openFileAsync(String filePath) {
    return new Promise<InputStream>((ret) -> {
        try {
            InputStream stream = openFile(filePath);
            ret.resolve(stream);
        } catch (IOException ex) {
            ret.reject(ex);
        }
    });
}
Also used : Promise(com.xenoage.utils.promise.Promise) InputStream(com.xenoage.utils.io.InputStream) JseInputStream(com.xenoage.utils.jse.io.JseInputStream) IOException(java.io.IOException)

Example 5 with InputStream

use of com.xenoage.utils.io.InputStream in project Zong by Xenoage.

the class JsePlatformUtils method openFileAsync.

@Override
public void openFileAsync(String filePath, AsyncResult<InputStream> callback) {
    try {
        InputStream stream = openFile(filePath);
        callback.onSuccess(stream);
    } catch (IOException ex) {
        callback.onFailure(ex);
    }
}
Also used : InputStream(com.xenoage.utils.io.InputStream) JseInputStream(com.xenoage.utils.jse.io.JseInputStream) IOException(java.io.IOException)

Aggregations

InputStream (com.xenoage.utils.io.InputStream)5 IOException (java.io.IOException)5 JseInputStream (com.xenoage.utils.jse.io.JseInputStream)3 AsyncResult (com.xenoage.utils.async.AsyncResult)1 Promise (com.xenoage.utils.promise.Promise)1 MusicXmlScoreDocFileReader (com.xenoage.zong.io.musicxml.in.MusicXmlScoreDocFileReader)1 Opus (com.xenoage.zong.io.musicxml.opus.Opus)1 OpusItem (com.xenoage.zong.io.musicxml.opus.OpusItem)1 OpusLink (com.xenoage.zong.io.musicxml.opus.OpusLink)1