Example usage for java.nio.file FileSystemAlreadyExistsException getMessage

List of usage examples for java.nio.file FileSystemAlreadyExistsException getMessage

Introduction

In this page you can find the example usage for java.nio.file FileSystemAlreadyExistsException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.schedulesdirect.api.ZipEpgClient.java

/**
 * Constructor/*from  www.j  av a  2 s.c  o m*/
 * @param zip The zip file to be used as the data source for this client implementation
 * @param baseUrl The base URL used to construct absolute URLs from relative URL data in the raw JSON
 * @throws IOException Thrown on any IO error reading the zip file
 */
public ZipEpgClient(final File zip, final String baseUrl) throws IOException {
    super(null, baseUrl);
    src = zip;
    progCache = new HashMap<String, Program>();
    artCache = new HashMap<>();
    URI fsUri;
    try {
        fsUri = new URI(String.format("jar:%s", zip.toURI()));
    } catch (URISyntaxException e1) {
        throw new RuntimeException(e1);
    }
    try {
        try {
            this.vfs = FileSystems.newFileSystem(fsUri, Collections.<String, Object>emptyMap());
        } catch (FileSystemAlreadyExistsException e) {
            this.vfs = FileSystems.getFileSystem(fsUri);
        }
        Path verFile = vfs.getPath(ZIP_VER_FILE);
        if (Files.exists(verFile)) {
            try (InputStream ins = Files.newInputStream(verFile)) {
                int ver = Integer.parseInt(IOUtils.toString(ins, ZIP_CHARSET.toString()));
                if (ver != ZIP_VER)
                    throw new IOException(
                            String.format("Zip file is not expected version! [v=%d; e=%d]", ver, ZIP_VER));
            }
        } else
            throw new IOException(String.format("Zip file of version %d required!", ZIP_VER));
        LOG.debug(String.format("Zip file format validated! [version=%d]", ZIP_VER));
        lineups = new HashMap<String, Lineup>();
        try (InputStream ins = Files.newInputStream(vfs.getPath(LINEUPS_LIST))) {
            String input = IOUtils.toString(ins, ZIP_CHARSET.toString());
            JSONObject o;
            try {
                o = Config.get().getObjectMapper().readValue(input, JSONObject.class);
            } catch (JsonParseException e) {
                throw new JsonEncodingException(String.format("ZipLineups: %s", e.getMessage()), e, input);
            }
            try {
                JSONArray lineups = o.getJSONArray("lineups");
                for (int i = 0; i < lineups.length(); ++i) {
                    JSONObject l = lineups.getJSONObject(i);
                    this.lineups.put(l.getString("uri"), new Lineup(l.getString("name"),
                            l.getString("location"), l.getString("uri"), l.getString("transport"), this));
                }
            } catch (JSONException e) {
                throw new InvalidJsonObjectException(String.format("ZipLineups: %s", e.getMessage()), e,
                        o.toString(3));
            }
        }
        String vfsKey = getSrcZipKey(zip);
        AtomicInteger i = CLNT_COUNT.get(vfsKey);
        if (i == null) {
            i = new AtomicInteger(0);
            CLNT_COUNT.put(vfsKey, i);
        }
        i.incrementAndGet();
        closed = false;
        detailsFetched = false;
    } catch (Throwable t) {
        if (vfs != null)
            try {
                close();
            } catch (IOException e) {
                LOG.error("IOError closing VFS!", e);
            }
        throw t;
    }
}