List of usage examples for java.io InvalidObjectException getMessage
public String getMessage()
From source file:com.bigtobster.pgnextractalt.commands.IOCommands.java
/** * Exports the currently loaded list of games to a text PGN file * * @param file File to be imported/* w w w . j av a 2 s .c o m*/ * @return Successful export of PGN file */ @CliCommand(value = IOCommands.EXPORT_COMMAND, help = IOCommands.EXPORT_COMMAND_HELP) public String exportPGN(@CliOption(key = { IOCommands.FILE_PATH_OPTION }, help = "Path (including file name) for exported PGN. File will be " + "created if it doesn't exist.", mandatory = true) final File file) { final PrintWriter printWriter; String failureDetails = null; final String filePath = file.getAbsolutePath(); try { if (!file.exists()) { //noinspection ResultOfMethodCallIgnored file.getParentFile().mkdirs(); //noinspection ResultOfMethodCallIgnored file.createNewFile(); } if (!file.canRead() || !file.canWrite()) { //noinspection ThrowCaughtLocally throw new InvalidObjectException(IOCommands.PGN_NOT_WRITABLE + IOCommands.SPACE + filePath); } printWriter = new PrintWriter(file); try { this.commandContext.getChessIO().exportPGN(printWriter); } finally { printWriter.close(); } } catch (final FileNotFoundException ignored) { failureDetails = IOCommands.CANNOT_CREATE_FILE + IOCommands.SPACE + filePath; } catch (final InvalidObjectException ioe) { failureDetails = ioe.getMessage(); } catch (final IOException ignored) { failureDetails = IOCommands.CANNOT_CREATE_FILE + IOCommands.SPACE + filePath; } if (failureDetails == null) { return IOCommands.SUCCESSFUL_EXPORT + IOCommands.SPACE + this.commandContext.getChessIO().getGames().size() + IOCommands.SPACE + IOCommands.GAMES_EXPORTED; } return IOCommands.FAILED_EXPORT + IOCommands.SPACE + failureDetails; }
From source file:com.daskiworks.ghwatch.backend.WatchedRepositoriesService.java
/** * Get watched repositories for view.//from w ww.jav a 2 s . c o m * * @param reloadStrategy if data should be reloaded from server * @return view data */ public WatchedRepositoriesViewData getNotificationStreamForView(ViewDataReloadStrategy reloadStrategy) { WatchedRepositoriesViewData nswd = new WatchedRepositoriesViewData(); WatchedRepositories ns = null; synchronized (TAG) { WatchedRepositories oldNs = Utils.readFromStore(TAG, context, persistFile); // user from store if possible, apply timeout of data from store if (reloadStrategy == ViewDataReloadStrategy.IF_TIMED_OUT) { ns = oldNs; if (ns != null && ns.getLastFullUpdateTimestamp() < (System.currentTimeMillis() - FORCE_VIEW_RELOAD_AFTER)) ns = null; } else if (reloadStrategy == ViewDataReloadStrategy.NEVER) { ns = oldNs; } // read from server try { if (ns == null && reloadStrategy != ViewDataReloadStrategy.NEVER) { ns = readFromServer(URL_NOTIFICATIONS); if (ns != null) { Utils.writeToStore(TAG, context, persistFile, ns); } } } catch (InvalidObjectException e) { nswd.loadingStatus = LoadingStatus.DATA_ERROR; Log.w(TAG, "Watched Repositories loading failed due data format problem: " + e.getMessage(), e); } catch (NoRouteToHostException e) { nswd.loadingStatus = LoadingStatus.CONN_UNAVAILABLE; Log.d(TAG, "Watched Repositories loading failed due connection not available."); } catch (AuthenticationException e) { nswd.loadingStatus = LoadingStatus.AUTH_ERROR; Log.d(TAG, "Watched Repositories loading failed due authentication problem: " + e.getMessage()); } catch (IOException e) { nswd.loadingStatus = LoadingStatus.CONN_ERROR; Log.w(TAG, "Watched Repositories loading failed due connection problem: " + e.getMessage()); } catch (JSONException e) { nswd.loadingStatus = LoadingStatus.DATA_ERROR; Log.w(TAG, "Watched Repositories loading failed due data format problem: " + e.getMessage()); } catch (Exception e) { nswd.loadingStatus = LoadingStatus.UNKNOWN_ERROR; Log.e(TAG, "Watched Repositories loading failed due: " + e.getMessage(), e); } // Show content from store because we are unable to read new one but want to show something if (ns == null) ns = oldNs; nswd.repositories = ns; return nswd; } }
From source file:com.daskiworks.ghwatch.backend.UnreadNotificationsService.java
/** * @param apiUrl API URL of Github object to get HTML url for. * @return response with URL from data//from w ww .java2s . com */ public StringViewData getGithubDataHtmlUrl(String apiUrl) { StringViewData nswd = new StringViewData(); try { if (apiUrl != null) { Response<JSONObject> resp = RemoteSystemClient.getJSONObjectFromUrl(context, authenticationManager.getGhApiCredentials(context), apiUrl, null); nswd.data = Utils.trimToNull(resp.data.getString("html_url")); if (nswd.data == null) { Log.w(TAG, "GithubDataHtmlUrl loading failed due data format problem: no 'html_url' field in response"); nswd.loadingStatus = LoadingStatus.DATA_ERROR; } } } catch (InvalidObjectException e) { nswd.loadingStatus = LoadingStatus.DATA_ERROR; Log.w(TAG, "NotificationStream loading failed due data format problem: " + e.getMessage(), e); } catch (NoRouteToHostException e) { nswd.loadingStatus = LoadingStatus.CONN_UNAVAILABLE; } catch (AuthenticationException e) { nswd.loadingStatus = LoadingStatus.AUTH_ERROR; } catch (IOException e) { Log.w(TAG, "GithubDataHtmlUrl loading failed due connection problem: " + e.getMessage()); nswd.loadingStatus = LoadingStatus.CONN_ERROR; } catch (JSONException e) { nswd.loadingStatus = LoadingStatus.DATA_ERROR; Log.w(TAG, "GithubDataHtmlUrl loading failed due data format problem: " + e.getMessage()); } catch (Exception e) { Log.e(TAG, "NotificationRead marking failed due: " + e.getMessage(), e); nswd.loadingStatus = LoadingStatus.UNKNOWN_ERROR; } return nswd; }
From source file:com.daskiworks.ghwatch.backend.UnreadNotificationsService.java
/** * Get unread notifications for view./*from www.j a va2 s. c om*/ * * @param reloadStrategy if data should be reloaded from server * @return info about notifications */ public NotificationStreamViewData getNotificationStreamForView(ViewDataReloadStrategy reloadStrategy) { NotificationStreamViewData nswd = new NotificationStreamViewData(); NotificationStream ns = null; synchronized (TAG) { NotificationStream oldNs = Utils.readFromStore(TAG, context, persistFile); // user from store if possible, apply timeout of data from store if (reloadStrategy == ViewDataReloadStrategy.IF_TIMED_OUT) { ns = oldNs; if (ns != null && ns.getLastFullUpdateTimestamp() < (System.currentTimeMillis() - FORCE_VIEW_RELOAD_AFTER)) ns = null; } else if (reloadStrategy == ViewDataReloadStrategy.NEVER) { ns = oldNs; } // read from server try { if (ns == null && reloadStrategy != ViewDataReloadStrategy.NEVER) { // we DO NOT use lastModified here because it returns only notifications newly added after given date, not all unread ns = readNotificationStreamFromServer(URL_NOTIFICATIONS, null); if (ns != null) { Utils.writeToStore(TAG, context, persistFile, ns); updateWidgets(); } } } catch (InvalidObjectException e) { nswd.loadingStatus = LoadingStatus.DATA_ERROR; Log.w(TAG, "NotificationStream loading failed due data format problem: " + e.getMessage(), e); } catch (NoRouteToHostException e) { nswd.loadingStatus = LoadingStatus.CONN_UNAVAILABLE; Log.d(TAG, "NotificationStream loading failed due connection not available."); } catch (AuthenticationException e) { nswd.loadingStatus = LoadingStatus.AUTH_ERROR; Log.d(TAG, "NotificationStream loading failed due authentication problem: " + e.getMessage()); } catch (IOException e) { nswd.loadingStatus = LoadingStatus.CONN_ERROR; Log.w(TAG, "NotificationStream loading failed due connection problem: " + e.getMessage()); } catch (JSONException e) { nswd.loadingStatus = LoadingStatus.DATA_ERROR; Log.w(TAG, "NotificationStream loading failed due data format problem: " + e.getMessage()); } catch (Exception e) { nswd.loadingStatus = LoadingStatus.UNKNOWN_ERROR; Log.e(TAG, "NotificationStream loading failed due: " + e.getMessage(), e); } // Show content from store because we are unable to read new one but want to show something if (ns == null) ns = oldNs; nswd.notificationStream = ns; return nswd; } }