Example usage for java.io IOException getLocalizedMessage

List of usage examples for java.io IOException getLocalizedMessage

Introduction

In this page you can find the example usage for java.io IOException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Retrieve possible download profiles from CouchPotato
 *///from www  . j  av  a 2 s.c  o m
public synchronized static void getStatusList() {
    if ("".equals(Preferences.get(Preferences.COUCHPOTATO_URL))) {
        return;
    }

    Thread thread = new Thread() {

        @Override
        public void run() {
            try {
                String result = makeApiCall(MESSAGE.STATUS_LIST.toString().toLowerCase());
                JSONObject jsonObject = new JSONObject(result);

                if (jsonObject.getBoolean("success")) {
                    JSONArray profileList = jsonObject.getJSONArray("list");
                    status = new HashMap<Integer, String>();
                    for (int i = 0; i < profileList.length(); i++) {
                        status.put(profileList.getJSONObject(i).getInt("id"),
                                profileList.getJSONObject(i).getString("label"));
                    }
                }
            } catch (IOException e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } catch (Throwable e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } finally {
                executingCommand = false;
            }
        }
    };
    executingCommand = true;
    thread.start();
}

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Retrieve possible download profiles from CouchPotato
 *//*from   w  w w .  java 2 s  .co m*/
public synchronized static void getProfiles() {
    if ("".equals(Preferences.get(Preferences.COUCHPOTATO_URL))) {
        return;
    }

    Thread thread = new Thread() {

        @Override
        public void run() {
            try {
                String result = makeApiCall(MESSAGE.PROFILE_LIST.toString().toLowerCase());
                JSONObject jsonObject = new JSONObject(result);

                if (jsonObject.getBoolean("success")) {
                    profiles = new HashMap<Integer, String>();
                    JSONArray profileList = jsonObject.getJSONArray("list");
                    for (int i = 0; i < profileList.length(); i++) {
                        profiles.put(profileList.getJSONObject(i).getInt("id"),
                                profileList.getJSONObject(i).getString("label"));
                    }
                }
            } catch (IOException e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } catch (Throwable e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } finally {
                executingCommand = false;
            }
        }
    };
    executingCommand = true;
    thread.start();
}

From source file:net.sf.jabref.exporter.FileActions.java

/**
 * Saves the database to file. Two boolean values indicate whether only
 * entries with a nonzero Globals.SEARCH value and only entries with a
 * nonzero Globals.GROUPSEARCH value should be saved. This can be used to
 * let the user save only the results of a search. False and false means all
 * entries are saved./*  w  w  w . ja  va2  s  .  c  om*/
 */
public static SaveSession saveDatabase(BibDatabase database, MetaData metaData, File file,
        JabRefPreferences prefs, boolean checkSearch, boolean checkGroup, Charset encoding,
        boolean suppressBackup) throws SaveException {

    boolean backup = prefs.getBoolean(JabRefPreferences.BACKUP);
    if (suppressBackup) {
        backup = false;
    }

    SaveSession session;
    BibEntry exceptionCause = null;
    try {
        session = new SaveSession(file, encoding, backup);
    } catch (Throwable e) {
        if (encoding != null) {
            LOGGER.error("Error from encoding: '" + encoding.displayName(), e);
        }
        // we must catch all exceptions to be able notify users that
        // saving failed, no matter what the reason was
        // (and they won't just quit JabRef thinking
        // everything worked and loosing data)
        throw new SaveException(e.getMessage(), e.getLocalizedMessage());
    }

    Map<String, EntryType> types = new TreeMap<>();

    // Get our data stream. This stream writes only to a temporary file,
    // until committed.
    try (VerifyingWriter writer = session.getWriter()) {

        // Write signature.
        FileActions.writeBibFileHeader(writer, encoding);

        // Write preamble if there is one.
        FileActions.writePreamble(writer, database.getPreamble());

        // Write strings if there are any.
        FileActions.writeStrings(writer, database);

        // Write database entries. Take care, using CrossRefEntry-
        // Comparator, that referred entries occur after referring
        // ones. Apart from crossref requirements, entries will be
        // sorted as they appear on the screen.
        List<BibEntry> sorter = FileActions.getSortedEntries(database, metaData, null, true);

        BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(), true);

        for (BibEntry entry : sorter) {
            exceptionCause = entry;

            // Check if we must write the type definition for this
            // entry, as well. Our criterion is that all non-standard
            // types (*not* customized standard types) must be written.
            EntryType entryType = entry.getType();

            if (EntryTypes.getStandardType(entryType.getName()) == null) {
                types.put(entryType.getName(), entryType);
            }

            // Check if the entry should be written.
            boolean write = true;

            if (checkSearch && !FileActions.nonZeroField(entry, BibtexFields.SEARCH)) {
                write = false;
            }

            if (checkGroup && !FileActions.nonZeroField(entry, BibtexFields.GROUPSEARCH)) {
                write = false;
            }

            if (write) {
                bibtexEntryWriter.write(entry, writer);
            }
        }

        // Write meta data.
        if (metaData != null) {
            metaData.writeMetaData(writer);
        }

        // Write type definitions, if any:
        if (!types.isEmpty()) {
            for (Map.Entry<String, EntryType> stringBibtexEntryTypeEntry : types.entrySet()) {
                EntryType type = stringBibtexEntryTypeEntry.getValue();
                if (type instanceof CustomEntryType) {
                    CustomEntryType tp = (CustomEntryType) type;
                    CustomEntryTypesManager.save(tp, writer);
                }
            }

        }

        //finally write whatever remains of the file, but at least a concluding newline
        if ((database.getEpilog() != null) && !(database.getEpilog().isEmpty())) {
            writer.write(database.getEpilog());
        } else {
            writer.write(Globals.NEWLINE);
        }
    } catch (IOException ex) {
        LOGGER.error("Could not write file", ex);
        session.cancel();
        // repairAfterError(file, backup, INIT_OK);
        throw new SaveException(ex.getMessage(), ex.getLocalizedMessage(), exceptionCause);
    }

    return session;

}

From source file:org.zenoss.zep.dao.impl.EventDaoHelper.java

private static String collectionToJsonDelimited(List<? extends Message> messages) throws ZepException {
    if (messages.isEmpty()) {
        return null;
    }/*from w  ww  .ja  v  a2s  . c  o  m*/
    final StringBuilder sb = new StringBuilder();
    try {
        for (Iterator<? extends Message> it = messages.iterator(); it.hasNext();) {
            sb.append(JsonFormat.writeAsString(it.next()));
            if (it.hasNext()) {
                sb.append(",\n");
            }
        }
    } catch (IOException e) {
        throw new ZepException(e.getLocalizedMessage(), e);
    }
    return sb.toString();
}

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Add movie to couchpotato//from   w w w. ja  v  a2 s .  com
 * 
 * @param messageHandler Handler
 * @param profile CouchPotato profile
 * @param idIMDb IMDB-ID
 * @param movieTitle Title of movie to add
 */
public static void addMovie(final Handler messageHandler, final String profile, final String idIMDb,
        final String movieTitle) {
    if (executingCommand || !Preferences.isSet(Preferences.COUCHPOTATO_URL)) {
        return;
    }

    Thread thread = new Thread() {

        @Override
        public void run() {
            try {
                String result = makeApiCall(MESSAGE.MOVIE_ADD.toString().toLowerCase(), "profile_id=" + profile,
                        "identifier=" + idIMDb, "title=" + movieTitle);

                JSONObject jsonObject = new JSONObject(result);
                result = (String) jsonObject.get("added");

                Message message = new Message();
                message.setTarget(messageHandler);
                message.what = MESSAGE.MOVIE_ADD.hashCode();
                message.obj = result;
                message.sendToTarget();

                Thread.sleep(500);
                CouchPotatoController.refreshMovies(messageHandler, "active,done");

            } catch (IOException e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
                sendUpdateMessageStatus(messageHandler, "Error");
            } catch (Throwable e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } finally {
                executingCommand = false;
                sendUpdateMessageStatus(messageHandler, "");
            }
        }
    };
    executingCommand = true;
    thread.start();
}

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Retrieve possible download profiles from CouchPotato
 * //ww w.  j a  v  a2s. c om
 * @param messageHandler Handler
 */
public synchronized static void getStatusList(final Handler messageHandler) {
    if (executingCommand || "".equals(Preferences.get(Preferences.COUCHPOTATO_URL))) {
        return;
    }

    Thread thread = new Thread() {

        @Override
        public void run() {
            try {
                String result = makeApiCall(MESSAGE.STATUS_LIST.toString().toLowerCase());

                JSONObject jsonObject = new JSONObject(result);

                if (jsonObject.getBoolean("success")) {
                    JSONArray profileList = jsonObject.getJSONArray("list");
                    status = new HashMap<Integer, String>();
                    for (int i = 0; i < profileList.length(); i++) {
                        status.put(profileList.getJSONObject(i).getInt("id"),
                                profileList.getJSONObject(i).getString("label"));
                    }

                    Message message = new Message();
                    message.setTarget(messageHandler);
                    message.what = MESSAGE.PROFILE_LIST.hashCode();
                    message.obj = status;
                    message.sendToTarget();
                }
            } catch (IOException e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } catch (Throwable e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } finally {
                executingCommand = false;
            }
        }
    };
    executingCommand = true;
    thread.start();
}

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Search for a movie based on title/*from  w w  w.  j a  v  a  2  s. c  o m*/
 * 
 * @param messageHandler Handler
 * @param searchTitle Movie title to search for
 */
public static void searchMovie(final Handler messageHandler, final String searchTitle) {
    if (!Preferences.isSet(Preferences.COUCHPOTATO_URL)) {
        return;
    }

    Thread thread = new Thread() {

        @Override
        public void run() {

            try {

                String result = makeApiCall(MESSAGE.MOVIE_SEARCH.toString().toLowerCase(), "q=" + searchTitle);
                JSONObject jsonObject = new JSONObject(result);
                MovieSearch movieList = null;

                if (!jsonObject.isNull("message") && !"".equals(jsonObject.getString("message"))) {
                    sendUpdateMessageStatus(messageHandler, "CouchPotato : " + jsonObject.getString("message"));
                } else {
                    SimpleJSONMarshaller jsonMarshaller = new SimpleJSONMarshaller(MovieSearch.class);
                    movieList = (MovieSearch) jsonMarshaller.unMarshal(jsonObject);
                }

                Message message = new Message();
                message.setTarget(messageHandler);
                message.what = MESSAGE.MOVIE_SEARCH.hashCode();
                message.obj = movieList;
                message.sendToTarget();
            } catch (IOException e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } catch (Throwable e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } finally {
                executingCommand = false;
            }
        }
    };
    executingRefreshMovies = true;
    executingCommand = true;
    thread.start();
}

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Retrieve possible download profiles from CouchPotat
 * //w  ww  . ja  v a2s  .  c  o  m
 * @param messageHandler Handler
 */
public synchronized static void getProfiles(final Handler messageHandler) {
    if (executingCommand || !Preferences.isSet(Preferences.COUCHPOTATO_URL)) {
        return;
    }

    Thread thread = new Thread() {

        @Override
        public void run() {
            try {
                String result = makeApiCall(MESSAGE.PROFILE_LIST.toString().toLowerCase());

                JSONObject jsonObject = new JSONObject(result);

                if (jsonObject.getBoolean("success") && profiles == null) {
                    profiles = new HashMap<Integer, String>();
                    JSONArray profileList = jsonObject.getJSONArray("list");
                    for (int i = 0; i < profileList.length(); i++) {
                        profiles.put(profileList.getJSONObject(i).getInt("id"),
                                profileList.getJSONObject(i).getString("label"));
                    }
                }

                Message message = new Message();
                message.setTarget(messageHandler);
                message.what = MESSAGE.PROFILE_LIST.hashCode();
                message.obj = profiles;
                message.sendToTarget();
            } catch (IOException e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } catch (Throwable e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } finally {
                executingCommand = false;
            }
        }
    };

    executingCommand = true;
    sendUpdateMessageStatus(messageHandler, MESSAGE.MOVIE_DELETE.toString());
    thread.start();
}

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Edit a move Based on ID and Profile_ID
 * /*from w  w w  . ja v  a  2 s . co m*/
 * @param messageHandler Handler
 * @param ids ID's of movies to edit
 * @param profile_id Profile ID of profile to edit the movies in
 */
public static void editMovie(final Handler messageHandler, final int profile_id, final int... ids) {
    if (!Preferences.isSet(Preferences.COUCHPOTATO_URL)) {
        return;
    }

    Thread thread = new Thread() {

        @Override
        public void run() {
            String movieIds = "";

            for (int i = 0; i < ids.length; i++) {
                if (i == 0)
                    movieIds += Integer.toString(ids[i]);
                else
                    movieIds += "," + Integer.toString(ids[i]);
            }

            try {
                String result = makeApiCall(MESSAGE.MOVIE_EDIT.toString().toLowerCase(),
                        "profile_id=" + profile_id, "id=" + movieIds);

                JSONObject jsonObject = new JSONObject(result);
                if (jsonObject.getBoolean("success")) {
                    // TODO: Resource bundle
                    sendUpdateMessageStatus(messageHandler, "Edited");
                } else {
                    // TODO: Resource bundle
                    sendUpdateMessageStatus(messageHandler, "Failed");
                }
                Thread.sleep(100);
                CouchPotatoController.refreshMovies(messageHandler, "active,done");

            } catch (IOException e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } catch (Throwable e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } finally {
                executingCommand = false;
                sendUpdateMessageStatus(messageHandler, "");
            }
        }
    };
    executingCommand = true;
    sendUpdateMessageStatus(messageHandler, MESSAGE.MOVIE_EDIT.toString());
    thread.start();
}

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Delete a move Based on ID//from  w w w .j a v a 2  s. c  om
 * 
 * @param messageHandler Handler
 * @param ids ID's of movies to delete
 */
public static void deleteMovie(final Handler messageHandler, final int... ids) {
    if (!Preferences.isSet(Preferences.COUCHPOTATO_URL)) {
        return;
    }

    Thread thread = new Thread() {

        @Override
        public void run() {
            String movieIds = "";

            for (int i = 0; i < ids.length; i++) {
                if (i == 0)
                    movieIds += Integer.toString(ids[i]);
                else
                    movieIds += "," + Integer.toString(ids[i]);
            }

            try {
                String result = makeApiCall(MESSAGE.MOVIE_DELETE.toString().toLowerCase(), "id=" + movieIds);
                JSONObject jsonObject = new JSONObject(result);
                if (jsonObject.getBoolean("success") && ids.length != 1) {
                    // TODO: Resource bundle
                    sendUpdateMessageStatus(messageHandler, "Deleted movies");
                } else if (jsonObject.getBoolean("success") && ids.length == 1) {
                    // TODO: Resource bundle
                    sendUpdateMessageStatus(messageHandler, "Deleted movie");
                } else {
                    // TODO: Resource bundle
                    sendUpdateMessageStatus(messageHandler, "Failed");
                }

                Thread.sleep(100);
                CouchPotatoController.refreshMovies(messageHandler, "");

            } catch (IOException e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } catch (Throwable e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } finally {
                executingCommand = false;
                sendUpdateMessageStatus(messageHandler, "");
            }
        }
    };
    executingCommand = true;
    sendUpdateMessageStatus(messageHandler, MESSAGE.MOVIE_DELETE.toString());
    thread.start();
}