List of usage examples for java.io IOException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.jaspersoft.jasperserver.rest.services.RESTRole.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { try {//w w w .j a va2s . c o m String searchCriteria = restUtils.extractResourceName(SERVICE_NAME, req.getPathInfo()); WSRole role = restUtils.unmarshal(WSRole.class, req.getInputStream()); role = restUtils.populateServiceObject(role); updateRole(role, restUtils.getWSRoleSearchCriteria(searchCriteria)); restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, ""); } catch (IOException e) { throw new ServiceException(e.getLocalizedMessage()); } catch (JAXBException e) { throw new ServiceException(e.getLocalizedMessage()); } }
From source file:com.att.aro.core.settings.impl.JvmSettings.java
private void createConfig(String configFilePath, List<String> values) { File configFile = new File(configFilePath); try (FileWriter fileWriter = new FileWriter(configFile)) { if (values != null && values.size() != 0) { for (String value : values) { fileWriter.write(value + "\n"); }//from w w w . j ava 2 s. c o m } } catch (IOException e) { throw new ARORuntimeException("Could not create config file: " + e.getLocalizedMessage(), e); } }
From source file:com.att.aro.core.settings.impl.JvmSettings.java
@Override public void saveConfigFile() { try {/*from w w w . j a va2 s .c o m*/ FileWriter writer = new FileWriter(CONFIG_FILE_PATH); LOGGER.debug("Persisting properties to: " + CONFIG_FILE_PATH); writer.close(); } catch (IOException e) { throw new ARORuntimeException("Could not save vm options file: " + e.getLocalizedMessage(), e); } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SelectGeneRawFileListener.java
@Override public void handleEvent(Event event) { // TODO Auto-generated method stub String path = this.selectRawFileUI.getPath(); if (path == null) return;/*from w w w. j a v a 2s .co m*/ if (path.contains("%")) { this.selectRawFileUI.displayMessage("File name can not contain percent ('%') symbol."); return; } File rawFile = new File(path); if (rawFile.exists()) { if (rawFile.isFile()) { if (!this.checkFormat(rawFile)) return; String newPath = this.dataType.getPath().getAbsolutePath() + File.separator + rawFile.getName(); File copiedRawFile = new File(newPath); if (!copiedRawFile.exists()) { try { FileUtils.copyFile(rawFile, copiedRawFile); ((GeneExpressionData) this.dataType).setRawFile(copiedRawFile); this.selectRawFileUI.displayMessage("File has been added"); WorkPart.updateSteps(); //to do: update files list UsedFilesPart.sendFilesChanged(dataType); } catch (IOException e) { // TODO Auto-generated catch block selectRawFileUI.displayMessage("File error: " + e.getLocalizedMessage()); e.printStackTrace(); } } else { this.selectRawFileUI.displayMessage("This file has already been added"); } } else { this.selectRawFileUI.displayMessage("This is a directory"); } } else { this.selectRawFileUI.displayMessage("This path does no exist"); } }
From source file:de.thm.arsnova.util.ImageUtils.java
/** * Gets the bytestream of an image url./*from ww w .j av a 2 s.c o m*/ * * @param imageUrl The image url as a {@link String} * @return The <code>byte[]</code> of the image on success, otherwise <code>null</code>. */ byte[] convertFileToByteArray(final String imageUrl) { try (final InputStream is = new URL(imageUrl).openStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final byte[] byteChunk = new byte[CHUNK_SIZE]; int n; while ((n = is.read(byteChunk)) > 0) { baos.write(byteChunk, 0, n); } baos.flush(); return baos.toByteArray(); } catch (IOException e) { logger.error(e.getLocalizedMessage()); } return null; }
From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java
/** * * @param source// ww w .j a v a2 s . c o m * @return */ public static String getClassNameQuietly(JavaSource source) { try { return getClassName(source); } catch (IOException ioe) { Logger.getLogger(JavaSourceHelper.class.getName()).log(Level.WARNING, ioe.getLocalizedMessage()); } return null; }
From source file:com.ibm.research.rdf.store.runtime.service.sql.StoreHelper.java
/** * Creates a tripleStore with defaults/*w w w . ja v a 2s . co m*/ * * @param conn * @param datasetName * @param names */ public static Store createDefaultStore(Connection conn, Backend backend, String schemaName, String datasetName, String predicateMappings, String tablespaceName) { boolean storeCreation = checkProperty("com.ibm.rdf.createStore"); boolean indexCreation = checkProperty("com.ibm.rdf.createIndex"); boolean generateSqlOnly = System.getProperty("com.ibm.rdf.generateStoreSQL") != null; int gidLenght = Constants.DEFAULT_GID_LENGTH; int colLenght = Constants.DEFAULT_COL_LENGTH; int bucketSizeDPH = Constants.DEFAULT_DPH_BUCKET_SIZE; int bucketSizeRPH = Constants.DEFAULT_RPH_BUCKET_SIZE; int defaultStoreStatus = Constants.DEFAULT_STORE_STATUS; if (predicateMappings != null) { DatasetGraph dsg = GraphColoringHashingFamily.loadDataset(predicateMappings); bucketSizeDPH = new GraphColoringHashingFamily(dsg, true, 3).getMaxColor() + 1; bucketSizeRPH = new GraphColoringHashingFamily(dsg, false, 3).getMaxColor() + 1; } java.util.Properties names = generateInternalNames(datasetName); String currentObj = ""; if (storeCreation) { SystemPredicateTableGeneration generation = new SystemPredicateTableGeneration(); // // create the DPH table // String t; if (bucketSizeDPH != Constants.DEFAULT_DPH_BUCKET_SIZE) { t = generation.getDirectPrimaryTableStatement(backend, gidLenght, colLenght, bucketSizeDPH); bucketSizeDPH = generation.getActualBucketSize(); } else { t = Sqls.getSqls(backend).getSql("defaultPrimarys"); } currentObj = names.getProperty(Constants.NAME_TABLE_DIRECT_PRIMARY_HASH); t = t.replaceFirst("%s", currentObj); if (Backend.shark == backend) { t = t.replaceFirst("%s", currentObj); // needed for shark in "CACHE TABLE %s" } if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); // // create the RPH table // currentObj = names.getProperty(Constants.NAME_TABLE_REVERSE_PRIMARY_HASH); if (bucketSizeRPH != Constants.DEFAULT_RPH_BUCKET_SIZE) { t = generation.getReversePrimaryTableStatement(backend, gidLenght, colLenght, bucketSizeRPH); bucketSizeRPH = generation.getActualBucketSize(); } else { t = Sqls.getSqls(backend).getSql("defaultReversePrimary"); } t = t.replaceFirst("%s", currentObj); if (Backend.shark == backend) { t = t.replaceFirst("%s", currentObj); // needed for shark in "CACHE TABLE %s" } if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); // // crerate the DS table // t = Sqls.getSqls(backend).getSql("defaultDirectSecondary"); currentObj = names.getProperty(Constants.NAME_TABLE_DIRECT_SECONDARY_HASH); t = t.replaceFirst("%s", currentObj); if (Backend.shark == backend) { t = t.replaceFirst("%s", currentObj); // needed for shark in "CACHE TABLE %s" } if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); if (backend == Backend.postgresql) { t = Sqls.getSqls(backend).getSql("triggerFunction"); doSql(conn, backend, t); t = Sqls.getSqls(backend).getSql("typeofTrigger"); t = t.replaceFirst("%s", names.getProperty(Constants.NAME_TABLE_DIRECT_SECONDARY_HASH)); doSql(conn, backend, t); } // // crerate the RS table // t = Sqls.getSqls(backend).getSql("defaultReverseSecondary"); currentObj = names.getProperty(Constants.NAME_TABLE_REVERSE_SECONDARY_HASH); t = t.replaceFirst("%s", currentObj); if (Backend.shark == backend) { t = t.replaceFirst("%s", currentObj); // needed for shark in "CACHE TABLE %s" } if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); // // crerate the LSTR table // t = Sqls.getSqls(backend).getSql("defaultLongStrings"); currentObj = names.getProperty(Constants.NAME_TABLE_LONG_STRINGS); t = t.replaceFirst("%s", currentObj); if (Backend.shark == backend) { t = t.replaceFirst("%s", currentObj); // needed for shark in "CACHE TABLE %s" } t = t.replaceFirst("%s", System.getProperty("com.ibm.rdf.longStringsLength", "2600")); if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); // // crerate the DIRECT_PREDS table // t = Sqls.getSqls(backend).getSql("defaultPredInfoTable"); t = t.replaceFirst("%s", datasetName + "_direct"); if (Backend.shark == backend) { t = t.replaceFirst("%s", datasetName + "_direct"); // needed for shark in "CACHE TABLE %s" } if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); // // crerate the REVERSE_PRED table // t = Sqls.getSqls(backend).getSql("defaultPredInfoTable"); t = t.replaceFirst("%s", datasetName + "_reverse"); if (Backend.shark == backend) { t = t.replaceFirst("%s", datasetName + "_reverse"); // needed for shark in "CACHE TABLE %s" } if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); // // crerate the BASIC_STATS table // t = Sqls.getSqls(backend).getSql("basicStats"); currentObj = names.getProperty(Constants.NAME_TABLE_BASIC_STATS); t = t.replaceFirst("%s", currentObj); if (Backend.shark == backend) { t = t.replaceFirst("%s", currentObj); // needed for shark in "CACHE TABLE %s" } if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); // // crerate the TOPKSTATS table // t = Sqls.getSqls(backend).getSql("topKStats"); currentObj = names.getProperty(Constants.NAME_TABLE_TOPK_STATS); t = t.replaceFirst("%s", currentObj); if (Backend.shark == backend) { t = t.replaceFirst("%s", currentObj); // needed for shark in "CACHE TABLE %s" } if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); // // crerate the DT table // t = Sqls.getSqls(backend).getSql("defaultDataTypeTable"); currentObj = names.getProperty(Constants.NAME_TABLE_DATATYPE); t = t.replaceFirst("%s", currentObj); if (Backend.shark == backend) { t = t.replaceFirst("%s", currentObj); // needed for shark in "CACHE TABLE %s" } if (tablespaceName != null) { t = t + " IN " + tablespaceName; } doSql(conn, backend, t); if (!(backend == Store.Backend.shark)) { // // crerate the datatype sequences // t = Sqls.getSqls(backend).getSql("defaultDataTypeSequence"); currentObj = names.getProperty(Constants.NAME_TABLE_DATATYPE); t = t.replaceFirst("%s", currentObj); doSql(conn, backend, t); t = Sqls.getSqls(backend).getSql("defaultDataLangSequence"); currentObj = names.getProperty(Constants.NAME_TABLE_DATATYPE); t = t.replaceFirst("%s", currentObj); doSql(conn, backend, t); } // insert into Config table if (backend == Store.Backend.shark) { BufferedWriter out = null; try { File loadFile = File.createTempFile("loadKBMetaDataRow", ".hiveql"); StringBuffer insert = new StringBuffer(); insert.append("\\N\t") // *entryid* .append(datasetName.toUpperCase()).append("\t") //storeName .append(1).append("\t") //version .append(names.getProperty(Constants.NAME_TABLE_DIRECT_PRIMARY_HASH)).append("\t") //directprimary .append(Integer.toString(bucketSizeDPH)).append("\t") //dprimarysize .append(names.getProperty(Constants.NAME_TABLE_DIRECT_SECONDARY_HASH)).append("\t") // directsecondary .append(names.getProperty(Constants.NAME_TABLE_REVERSE_PRIMARY_HASH)).append("\t") //reverseprimary .append(Integer.toString(bucketSizeRPH)).append("\t") //rprimarysize .append(names.getProperty(Constants.NAME_TABLE_REVERSE_SECONDARY_HASH)).append("\t") //reversesecondary .append(names.getProperty(Constants.NAME_TABLE_LONG_STRINGS)).append("\t") //longStrings .append(Integer.toString(colLenght)).append("\t") //maxStringLen .append(Integer.toString(gidLenght)).append("\t") //gidMaxStringLen, .append("\\N").append("\t") // *haslongstrings* .append(names.getProperty(Constants.NAME_TABLE_BASIC_STATS)).append("\t") //basicStatsTable, .append(names.getProperty(Constants.NAME_TABLE_TOPK_STATS)).append("\t") // topKStatsTable, .append("\\N").append("\t") //*laststatsupdated* .append("\\N").append("\t") //predicateMappings, .append("\\N").append("\t") // systemPredicateTable, .append(Integer.toString(defaultStoreStatus)).append("\t") // |status|, .append(names.getProperty(Constants.NAME_TABLE_DATATYPE)).append("\t") // |dataTypeTable| .append("\\N"); // *hasspills* //.append("\n"); out = new BufferedWriter(new FileWriter(loadFile, false)); out.write(insert.toString()); String loadHiveQl = Sqls.getSqls(backend).getSql("loadFromFile"); loadHiveQl = loadHiveQl.replaceFirst("%s", datasetName).replaceFirst("%c", loadFile.getAbsolutePath()); doSql(conn, backend, loadHiveQl); } catch (IOException e) { log.error(e); e.printStackTrace(); System.out.println(e.getLocalizedMessage()); } finally { if (out != null) { try { out.close(); } catch (IOException e) { log.error(e); e.printStackTrace(); System.out.println(e.getLocalizedMessage()); } } } } else { String insert = Sqls.getSqls(backend).getSql("defaultDataset"); insert = insert.replaceFirst("%s", datasetName); if (generateSqlOnly) { // // We simulate here the same replacement of the ? SQL parameters with values that executeUpdate does // in terms of the clob, we no longer load it with the predicate_mappings content // insert = insert.replaceFirst("\\?", "'" + datasetName + "'"); insert = insert.replaceFirst("\\?", "'" + names.getProperty(Constants.NAME_TABLE_DIRECT_PRIMARY_HASH) + "'"); insert = insert.replaceFirst("\\?", Integer.toString(bucketSizeDPH)); insert = insert.replaceFirst("\\?", "'" + names.getProperty(Constants.NAME_TABLE_DIRECT_SECONDARY_HASH) + "'"); insert = insert.replaceFirst("\\?", "'" + names.getProperty(Constants.NAME_TABLE_REVERSE_PRIMARY_HASH) + "'"); insert = insert.replaceFirst("\\?", Integer.toString(bucketSizeRPH)); insert = insert.replaceFirst("\\?", "'" + names.getProperty(Constants.NAME_TABLE_REVERSE_SECONDARY_HASH) + "'"); insert = insert.replaceFirst("\\?", "'" + names.getProperty(Constants.NAME_TABLE_LONG_STRINGS) + "'"); insert = insert.replaceFirst("\\?", Integer.toString(colLenght)); insert = insert.replaceFirst("\\?", Integer.toString(gidLenght)); insert = insert.replaceFirst("\\?", "'" + names.getProperty(Constants.NAME_TABLE_BASIC_STATS) + "'"); insert = insert.replaceFirst("\\?", "'" + names.getProperty(Constants.NAME_TABLE_TOPK_STATS) + "'"); insert = insert.replaceFirst("\\?", "null"); insert = insert.replaceFirst("\\?", "null"); insert = insert.replaceFirst("\\?", "'" + names.getProperty(Constants.NAME_TABLE_DATATYPE) + "'"); insert = insert.replaceFirst("\\?", Integer.toString(defaultStoreStatus)); doSql(conn, backend, insert); } else { // // we no longer load the predicate_mappings file to the clob // SQLExecutor.executeUpdate(conn, insert, datasetName, names.getProperty(Constants.NAME_TABLE_DIRECT_PRIMARY_HASH), bucketSizeDPH, names.getProperty(Constants.NAME_TABLE_DIRECT_SECONDARY_HASH), names.getProperty(Constants.NAME_TABLE_REVERSE_PRIMARY_HASH), bucketSizeRPH, names.getProperty(Constants.NAME_TABLE_REVERSE_SECONDARY_HASH), names.getProperty(Constants.NAME_TABLE_LONG_STRINGS), colLenght, gidLenght, names.getProperty(Constants.NAME_TABLE_BASIC_STATS), names.getProperty(Constants.NAME_TABLE_TOPK_STATS), "", "", names.getProperty(Constants.NAME_TABLE_DATATYPE), defaultStoreStatus); } } /* * // Standard Datatype entries insert = Sqls.getSqls().getSql("defaultDataTypeEntry"); insert = insert.replaceFirst("%s", names * .getProperty(Constants.NAME_TABLE_DATATYPE)); * * stmt = null; try { stmt = conn.prepareStatement(insert); for (i = 1; i < TypeMap.getTypedIRIArray().length; i++) { stmt.setInt(1, * TypeMap.DATATYPE_IDS_START + i); stmt.setString(2, TypeMap.getTypedIRIArray()[i]); stmt.addBatch(); } for (i = 0; i < * TypeMap.getLangArray().length; i++) { stmt.setInt(1, TypeMap.getLangArray()[i].langcode); stmt.setString(2, * TypeMap.getLangArray()[i].langstring); stmt.addBatch(); } stmt.executeBatch(); } catch (SQLException e) { throw new * RdfStoreException(e.getLocalizedMessage(),e); } finally { DB2CloseObjects.close(stmt); } */ if (!generateSqlOnly) { if (backend == Backend.db2) { setupRunStatsProfile(conn, backend, names.getProperty(Constants.NAME_TABLE_DIRECT_PRIMARY_HASH), names.getProperty(Constants.NAME_TABLE_DIRECT_SECONDARY_HASH), names.getProperty(Constants.NAME_TABLE_REVERSE_PRIMARY_HASH), names.getProperty(Constants.NAME_TABLE_REVERSE_SECONDARY_HASH), names.getProperty(Constants.NAME_TABLE_LONG_STRINGS), bucketSizeDPH, bucketSizeRPH, getSchema(conn, schemaName)); } } } if (indexCreation) { createIndexes(conn, backend, names, datasetName); } if (generateSqlOnly) { return null; } else { return StoreManager.connectStore(conn, backend, schemaName, datasetName, Context.defaultContext); } }
From source file:ch.netcetera.eclipse.projectconfig.core.configurationcommands.DownloadProjectConfigurationCommand.java
/** * Downloads a file from a local (file://) source. * * @param fileUrl the file url/* w w w.ja v a2 s. co m*/ * @param targetFile the target file * @return the status */ private IStatus downloadFileFromFile(String fileUrl, File targetFile) { IStatus status = Status.OK_STATUS; try { URI uri = new URI(fileUrl); if (uri.getAuthority() == null) { File sourceFile = new File(uri); if (sourceFile.canRead()) { OutputStream outputStream = null; InputStream inputStream = null; try { outputStream = new FileOutputStream(targetFile); inputStream = new FileInputStream(sourceFile); copyFile(inputStream, outputStream); } finally { IOUtil.closeSilently(outputStream); IOUtil.closeSilently(inputStream); } } else { status = createStatus(IStatus.ERROR, getTextAccessor().getText("error.cannot.read.local.file")); } } else { status = createStatus(IStatus.ERROR, getTextAccessor().getText("error.cannot.read.local.file")); } } catch (IOException e) { status = createStatus(IStatus.ERROR, e.getLocalizedMessage(), e); } catch (URISyntaxException e) { status = createStatus(IStatus.ERROR, e.getLocalizedMessage(), e); } return status; }
From source file:com.owncloud.android.services.AdvancedFileAlterationListener.java
public void onFileCreate(final File file, int delay) { if (file != null) { uploadMap.put(file.getAbsolutePath(), null); String mimetypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath()); Long lastModificationTime = file.lastModified(); final Locale currentLocale = context.getResources().getConfiguration().locale; if ("image/jpeg".equalsIgnoreCase(mimetypeString) || "image/tiff".equalsIgnoreCase(mimetypeString)) { try { ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath()); String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME); if (!TextUtils.isEmpty(exifDate)) { ParsePosition pos = new ParsePosition(0); SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", currentLocale); sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID())); Date dateTime = sFormatter.parse(exifDate, pos); lastModificationTime = dateTime.getTime(); }//from w w w . j a v a2s . c om } catch (IOException e) { Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage()); } } final Long finalLastModificationTime = lastModificationTime; Runnable runnable = new Runnable() { @Override public void run() { PersistableBundleCompat bundle = new PersistableBundleCompat(); bundle.putString(AutoUploadJob.LOCAL_PATH, file.getAbsolutePath()); bundle.putString(AutoUploadJob.REMOTE_PATH, FileStorageUtils.getInstantUploadFilePath(currentLocale, syncedFolder.getRemotePath(), file.getName(), finalLastModificationTime, syncedFolder.getSubfolderByDate())); bundle.putString(AutoUploadJob.ACCOUNT, syncedFolder.getAccount()); bundle.putInt(AutoUploadJob.UPLOAD_BEHAVIOUR, syncedFolder.getUploadAction()); new JobRequest.Builder(AutoUploadJob.TAG).setExecutionWindow(30_000L, 80_000L) .setRequiresCharging(syncedFolder.getChargingOnly()) .setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobRequest.NetworkType.UNMETERED : JobRequest.NetworkType.ANY) .setExtras(bundle).setPersisted(false).setRequirementsEnforced(true) .setUpdateCurrent(false).build().schedule(); uploadMap.remove(file.getAbsolutePath()); } }; uploadMap.put(file.getAbsolutePath(), runnable); handler.postDelayed(runnable, delay); } }
From source file:ch.netcetera.eclipse.projectconfig.core.configurationcommands.DownloadProjectConfigurationCommand.java
/** * Downloads a file from a remote (http(s)://) source. * * @param fileUrl the file url/*w w w. j a va2 s .c om*/ * @param targetFile the target file * @return the status */ private IStatus downloadFileFromHTTP(String fileUrl, File targetFile) { IStatus status = Status.OK_STATUS; HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(fileUrl); int httpStatus; try { HttpResponse response = httpClient.execute(httpGet); httpStatus = response.getStatusLine().getStatusCode(); if (httpStatus != HttpStatus.SC_OK) { status = createStatus(IStatus.ERROR, response.getStatusLine().getReasonPhrase()); } else { OutputStream outputStream = null; InputStream inputStream = null; try { // write response to the file outputStream = new FileOutputStream(targetFile); inputStream = response.getEntity().getContent(); copyFile(inputStream, outputStream); } finally { IOUtil.closeSilently(outputStream); IOUtil.closeSilently(inputStream); } } } catch (IOException e) { status = createStatus(IStatus.ERROR, e.getLocalizedMessage(), e); } return status; }