List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:de.unibi.cebitec.bibiserv.util.visualizer.AbstractTest.java
private static DataSource derbydb() throws Exception { EmbeddedDataSource ds = new EmbeddedDataSource(); String db = "test/testdb_" + System.currentTimeMillis(); // check if database exists File db_dir = new File(db); if (db_dir.exists()) { try {/*from w w w .j av a2 s. co m*/ FileUtils.deleteDirectory(db_dir); } catch (IOException e) { LOG.error(e); assertTrue(e.getMessage(), false); } } ds.setDatabaseName(db); ds.setCreateDatabase("create"); Connection con = ds.getConnection(); Statement stmt = con.createStatement(); // read SQL Statement from file BufferedReader r = new BufferedReader( new InputStreamReader(TestRAEDA.class.getResourceAsStream("/status.sql"))); String line; StringBuilder sql = new StringBuilder(); while ((line = r.readLine()) != null) { // skip commend lines if (!line.startsWith("--")) { sql.append(line); sql.append('\n'); } } r.close(); // execute sqlcmd's for (String sqlcmd : sql.toString().split(";")) { sqlcmd = sqlcmd.trim(); // ignore trailing/ending whitespaces sqlcmd = sqlcmd.replaceAll("\n\n", "\n"); // remove double newline if (sqlcmd.length() > 1) { // if string contains more than one char, execute sql cmd LOG.debug(sqlcmd + "\n"); stmt.execute(sqlcmd); } } // close stmt stmt.close(); return ds; }
From source file:gov.nist.appvet.shared.FileUtil.java
public static synchronized boolean copyFile(String sourceFilePath, String destFilePath) { if (sourceFilePath == null || destFilePath == null) { return false; }//from www . jav a 2 s . c o m File sourceFile = new File(sourceFilePath); if (!sourceFile.exists()) { return false; } File destFile = new File(destFilePath); try { Files.copy(sourceFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (final IOException e) { log.error(e.getMessage()); return false; } finally { sourceFile = null; destFile = null; } return true; }
From source file:net.dv8tion.discord.Yui.java
private static void relaunchInUTF8() throws InterruptedException, UnsupportedEncodingException { System.out.println("BotLauncher: We are not running in UTF-8 mode! This is a problem!"); System.out.println("BotLauncher: Relaunching in UTF-8 mode using -Dfile.encoding=UTF-8"); String[] command = new String[] { "java", "-Dfile.encoding=UTF-8", "-jar", Yui.getThisJarFile().getAbsolutePath() }; //Relaunches the bot using UTF-8 mode. ProcessBuilder processBuilder = new ProcessBuilder(command); processBuilder.inheritIO(); //Tells the new process to use the same command line as this one. try {/* w w w .j a v a 2s . c o m*/ Process process = processBuilder.start(); process.waitFor(); //We wait here until the actual bot stops. We do this so that we can keep using the same command line. System.exit(process.exitValue()); } catch (IOException e) { if (e.getMessage().contains("\"java\"")) { System.out.println( "BotLauncher: There was an error relaunching the bot. We couldn't find Java to launch with."); System.out.println("BotLauncher: Attempted to relaunch using the command:\n " + StringUtils.join(command, " ", 0, command.length)); System.out.println( "BotLauncher: Make sure that you have Java properly set in your Operating System's PATH variable."); System.out.println("BotLauncher: Stopping here."); } else { e.printStackTrace(); } } }
From source file:com.bah.applefox.main.plugins.pageranking.utilities.PRtoFile.java
public static boolean writeToFile(String[] args) { String fileName = args[16];/*from ww w. java 2 s. c om*/ File f = new File(fileName); try { f.createNewFile(); OutputStream file = new FileOutputStream(f); OutputStream buffer = new BufferedOutputStream(file); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(createMap(args)); out.flush(); out.close(); } catch (IOException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } return false; } catch (AccumuloException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } return false; } catch (AccumuloSecurityException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } return false; } catch (TableNotFoundException e) { if (e.getMessage() != null) { log.error(e.getMessage()); } else { log.error(e.getStackTrace()); } return false; } return true; }
From source file:com.example.admin.processingboilerplate.JsonIO.java
public static StringBuilder loadString(String url) { StringBuilder sb = new StringBuilder(); try {//from w w w .j a va 2s.c o m URLConnection uc = (new URL(url)).openConnection(); HttpURLConnection con = url.startsWith("https") ? (HttpsURLConnection) uc : (HttpURLConnection) uc; try { con.setReadTimeout(6000); con.setConnectTimeout(6000); con.setRequestMethod("GET"); con.setDoInput(true); con.setRequestProperty("User-Agent", USER_AGENT); sb = load(con); } catch (IOException e) { Log.e("loadJson", e.getMessage(), e); } finally { con.disconnect(); } } catch (IOException e) { Log.e("loadJson", e.getMessage(), e); } return sb; }
From source file:com.streamsets.pipeline.stage.processor.statsaggregation.ConfigHelper.java
public static PipelineConfigurationJson readPipelineConfig(String pipelineConfigJson, Stage.Context context, List<Stage.ConfigIssue> issues) { PipelineConfigurationJson pipelineConfigurationJson = null; try {// w ww. j a va2 s . co m pipelineConfigurationJson = ObjectMapperFactory.get().readValue( new String(Base64.decodeBase64(pipelineConfigJson)), PipelineConfigurationJson.class); } catch (IOException ex) { issues.add(context.createConfigIssue(Groups.STATS.getLabel(), "pipelineConfigJson", Errors.STATS_00, ex.getMessage(), ex)); } return pipelineConfigurationJson; }
From source file:de.egore911.versioning.deployer.performer.PerformReplacement.java
private static void perform(File directory, List<String> wildcards, List<ReplacementPair> replacements) { if (!directory.exists()) { LOG.error("Directory {} does not exist", directory); return;/*w ww .j ava 2 s .c om*/ } if (!directory.isDirectory()) { LOG.error("{} is not a directory", directory); return; } IOFileFilter fileFilter = new WildcardFileFilter(wildcards); Collection<File> files = FileUtils.listFiles(directory, fileFilter, TrueFileFilter.INSTANCE); for (File file : files) { try { String content = FileUtils.readFileToString(file); for (ReplacementPair replacement : replacements) { content = content.replace("${versioning:" + replacement.variable + "}", replacement.value); } FileUtils.write(file, content); } catch (IOException e) { LOG.error(e.getMessage(), e); } } }
From source file:com.stratio.ingestion.utils.IngestionUtils.java
public static Map<String, String> readConfig() { Map<String, String> settings = new HashMap<>(); try {//w w w .j av a 2 s . c o m BufferedReader br = new BufferedReader(new FileReader(getRelativeDir("conf/ingestion/ingestion.conf"))); String line = br.readLine(); while (line != null) { String[] lineArray = line.trim().split("="); settings.put(lineArray[0], lineArray[1]); line = br.readLine(); } } catch (IOException e) { logger.error(e.getMessage()); //TODO why we don't manage the exception. } return settings; }
From source file:cc.softwarefactory.lokki.android.utilities.gcm.GcmHelper.java
private static void registerInBackground(final Context context) { new AsyncTask<Void, Void, String>() { @Override// w ww. j a v a 2 s . c om protected String doInBackground(Void... params) { try { if (gcm == null) { gcm = GoogleCloudMessaging.getInstance(context); } regid = gcm.register(SENDER_ID); sendRegistrationIdToBackend(context); storeRegistrationId(context, regid); return "Device registered, registration ID = " + regid; } catch (IOException ex) { return "Error :" + ex.getMessage(); } } @Override protected void onPostExecute(String msg) { Log.e(TAG, msg); } }.execute(null, null, null); }
From source file:net.noday.core.dnspod.Dnspod.java
public static void domainRemove(String dnspodDomainId) { Document doc;//from w w w . j a v a 2 s.com try { doc = Jsoup.connect(url_domainRemove).data(data).data("domain_id", dnspodDomainId).userAgent(user_agent) .post(); JSONObject o = JSON.parseObject(doc.body().text()); String code = o.getJSONObject("status").getString("code"); if (!StringUtils.equals(code, "1")) { throw new DnspodException(o.getJSONObject("status").getString("message")); } } catch (IOException e) { throw new DnspodException(e.getMessage()); } }