List of usage examples for java.io File getParent
public String getParent()
null
if this pathname does not name a parent directory. From source file:eu.udig.catalog.jgrass.operations.SetActiveRegionToMapsAction.java
public void run(IAction action) { IRunnableWithProgress operation = new IRunnableWithProgress() { public void run(final IProgressMonitor pm) throws InvocationTargetException, InterruptedException { Display.getDefault().syncExec(new Runnable() { public void run() { final List<?> toList = selection.toList(); Envelope bounds = null; try { pm.beginTask("Set active region to maps bounds...", toList.size()); try { JGrassRegion currentRegion = null; JGrassMapEnvironment grassMapEnvironment = null; for (Object object : toList) { if (object instanceof JGrassMapGeoResource) { JGrassMapGeoResource mr = (JGrassMapGeoResource) object; JGrassRegion fileWindow = mr.getFileWindow(); if (currentRegion == null) { currentRegion = mr.getActiveWindow(); grassMapEnvironment = mr.getjGrassMapEnvironment(); }//from www. j a va 2 s . c om Envelope envelope = fileWindow.getEnvelope(); if (bounds == null) { bounds = envelope; } else { bounds.expandToInclude(envelope); } } pm.worked(1); } String code = null; try { CoordinateReferenceSystem jGrassCrs = grassMapEnvironment .getCoordinateReferenceSystem(); try { Integer epsg = CRS.lookupEpsgCode(jGrassCrs, true); code = "EPSG:" + epsg; } catch (Exception e) { // try non epsg code = CRS.lookupIdentifier(jGrassCrs, true); } } catch (Exception e) { e.printStackTrace(); } JGrassRegion newActiveRegion = JGrassRegion.adaptActiveRegionToEnvelope(bounds, currentRegion); File windFile = grassMapEnvironment.getWIND(); JGrassRegion.writeWINDToMapset(windFile.getParent(), newActiveRegion); IMap activeMap = ApplicationGIS.getActiveMap(); IBlackboard blackboard = activeMap.getBlackboard(); ActiveRegionStyle style = (ActiveRegionStyle) blackboard .get(ActiveregionStyleContent.ID); if (style == null) { style = ActiveregionStyleContent.createDefault(); } style.north = (float) newActiveRegion.getNorth(); style.south = (float) newActiveRegion.getSouth(); style.east = (float) newActiveRegion.getEast(); style.west = (float) newActiveRegion.getWest(); style.rows = newActiveRegion.getRows(); style.cols = newActiveRegion.getCols(); style.windPath = windFile.getAbsolutePath(); style.crsString = code; blackboard.put(ActiveregionStyleContent.ID, style); ILayer activeRegionMapGraphic = JGrassPlugin.getDefault() .getActiveRegionMapGraphic(); activeRegionMapGraphic.refresh(null); } catch (IOException e) { e.printStackTrace(); String message = "Problems occurred while setting the new active region."; ExceptionDetailsDialog.openError("Information", message, IStatus.ERROR, JGrassPlugin.PLUGIN_ID, e); } } finally { pm.done(); } } }); } }; PlatformGIS.runInProgressDialog("Set active region...", true, operation, true); }
From source file:aes.pica.touresbalon.tb_serviciosbolivariano.ServiciosBolivarianos.java
@Override public boolean cancelarReserva(int ordenId) { String nombreArchivo = Constantes.NAME_RESERVAS + ordenId + Constantes.CSV_FILE; Random numaleatorio = new Random(3816L); try {// w ww . j av a2 s . c o m File archivoConsulta = FileUtils.getFile(rutaReservas, nombreArchivo); String nombreArchivoNvo = archivoConsulta.getParent() + "/auxiliar" + String.valueOf(Math.abs(numaleatorio.nextInt())) + ".txt"; File archivoConsultaNvo = new File(nombreArchivoNvo); if (archivoConsulta != null && archivoConsulta.exists()) { br = new BufferedReader(new FileReader(archivoConsulta)); String linea = ""; while ((linea = br.readLine()) != null) { if (linea.indexOf(ordenId + ",") != -1) { System.out.println("" + linea); String lineaNva = null; /*for (int i = 0; i <= linea.length(); i++){ System.out.println("Caracter " + i + ": " + linea.charAt(i)); if (POSICION_CANCELAR == i) { lineaNva.concat("C"); } else { lineaNva.concat(String.valueOf(linea.charAt(i))); } }*/ StringTokenizer token = new StringTokenizer(linea, "."); int c = 1; while (token.hasMoreTokens()) { if (POSICION_CANCELAR == c) { lineaNva.concat("C"); } else { System.out.println(token.nextToken()); lineaNva.concat(token.nextToken()); } c++; } EcribirFichero(archivoConsultaNvo, linea); } else { EcribirFichero(archivoConsulta, linea); } } BorrarFichero(archivoConsulta); archivoConsultaNvo.renameTo(archivoConsulta); br.close(); } else { System.out.println("No existe archivo: " + nombreArchivo + " en el directorio: " + rutaReservas); } return true; } catch (IOException ex) { System.err.println(ex.toString()); } return false; }
From source file:de.ks.text.AsciiDocParser.java
protected File createDataDir(File file) { String child = file.getName().contains(".") ? file.getName().substring(0, file.getName().lastIndexOf('.')) : file.getName();/*w w w . j a va2s. com*/ File dataDir = new File(file.getParent(), child + DATADIR_NAME); log.debug("using target data dir {}", dataDir); if (!dataDir.exists()) { try { java.nio.file.Files.createDirectories(dataDir.toPath()); } catch (IOException e) { log.error("Could not create datadir {}", dataDir, e); throw new RuntimeException(e); } } return dataDir; }
From source file:br.itecbrazil.serviceftpcliente.model.ThreadEnvio.java
private boolean gravarBackup(File arquivo) { logger.info("Gravando backup do arquivo " + arquivo.getName() + ". Thread: " + Thread.currentThread().getName()); String pathDoBackUp = arquivo.getParent().concat(File.separator).concat("backup"); File diretorio = new File(pathDoBackUp); FileReader fr = null;/*from w w w . j av a 2 s . c o m*/ BufferedReader br = null; FileWriter fw = null; BufferedWriter bw = null; try { if (!diretorio.exists()) { diretorio.mkdir(); } File arquivoBackUp = new File(pathDoBackUp.concat(File.separator).concat(arquivo.getName())); fr = new FileReader(arquivo); br = new BufferedReader(fr); fw = new FileWriter(arquivoBackUp); bw = new BufferedWriter(fw); String linha = br.readLine(); while (linha != null) { bw.write(linha); bw.newLine(); bw.flush(); coteudoFileTransfer.append(linha); linha = br.readLine(); } } catch (FileNotFoundException ex) { loggerExceptionEnvio.info(ex); return false; } catch (IOException ex) { loggerExceptionEnvio.info(ex); return false; } finally { try { if (fr != null) fr.close(); if (br != null) br.close(); } catch (IOException ex) { loggerExceptionEnvio.info(ex); return false; } } return true; }
From source file:com.liferay.ide.maven.core.util.DefaultMaven2OsgiConverter.java
private String getGroupIdFromPackage(File artifactFile) { try {/*from w ww .java2 s.com*/ /* get package names from jar */ Set packageNames = new HashSet(); JarFile jar = new JarFile(artifactFile, false); Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.getName().endsWith(".class")) { File f = new File(entry.getName()); String packageName = f.getParent(); if (packageName != null) { packageNames.add(packageName); } } } /* find the top package */ String[] groupIdSections = null; for (Iterator it = packageNames.iterator(); it.hasNext();) { String packageName = (String) it.next(); String[] packageNameSections = packageName.split("\\" + FILE_SEPARATOR); if (groupIdSections == null) { /* first candidate */ groupIdSections = packageNameSections; } else // if ( packageNameSections.length < groupIdSections.length ) { /* * find the common portion of current package and previous selected groupId */ int i; for (i = 0; (i < packageNameSections.length) && (i < groupIdSections.length); i++) { if (!packageNameSections[i].equals(groupIdSections[i])) { break; } } groupIdSections = new String[i]; System.arraycopy(packageNameSections, 0, groupIdSections, 0, i); } } if ((groupIdSections == null) || (groupIdSections.length == 0)) { return null; } /* only one section as id doesn't seem enough, so ignore it */ if (groupIdSections.length == 1) { return null; } StringBuffer sb = new StringBuffer(); for (int i = 0; i < groupIdSections.length; i++) { sb.append(groupIdSections[i]); if (i < groupIdSections.length - 1) { sb.append('.'); } } return sb.toString(); } catch (IOException e) { /* we took all the precautions to avoid this */ throw new RuntimeException(e); } }
From source file:edu.pitt.dbmi.facebase.hd.FileManager.java
/** copies files to mounted truecrypt volume * Assumes all Instruction objects and their associated Files are in order. * Assumes suitably large truecrypt volume is mounted and writable and can hold all of the data. * Double-checks that data will fit onto volume (although this fact has also been established elsewhere by now). * This method will block for a very long time if large amounts of data are being copied. * //from w w w .java 2s . com * @return true if copy effort succeeded */ public boolean copyFilesToVolume(ArrayList<Instructions> alival) { log.debug("FileManager.copyFilesToVolume() called."); long totalSize = 0; HashMap<File, String> hmfs = new HashMap<File, String>(); for (Instructions i : alival) { hmfs.put(i.getFile(), i.getRelativePathToFileInArchive()); totalSize += i.getFile().length(); } long volSize = 0; File trueCryptVolFile = new File(this.getTrueCryptPath()); volSize = trueCryptVolFile.length(); if (totalSize > volSize) { } else { } try { for (File f : hmfs.keySet()) { File tcvpPlusRptfia = new File(trueCryptVolumePath + hmfs.get(f)); File parentDir = new File(tcvpPlusRptfia.getParent()); if (f.isFile()) { if (parentDir.isDirectory()) { } else { parentDir.mkdirs(); if (parentDir.isDirectory()) { } } log.debug("About to copy with FileUtils.copyFileToDirectory() using two args, FILE, DIR:"); log.debug(f + " " + parentDir); FileUtils.copyFileToDirectory(f, parentDir); } } } catch (IOException ioe) { String errorString = "FileManager caught an ioe in copyFilesToVolume()" + ioe.toString(); String logString = ioe.getMessage(); edu.pitt.dbmi.facebase.hd.HumanDataController.addError(errorString, logString); log.error(errorString, ioe); return false; } //Uncomment these next 2 lines to simulate errors //edu.pitt.dbmi.facebase.hd.HumanDataController.addError("BADSTUFFmessage","BADSTUFFlog"); //log.error("FileManager caught an ioe in copyFilesToVolume()BADSTUFF", new IOException()); return true; }
From source file:br.upe.ecomp.dosa.controller.chart.FileLineChartManager.java
private Panel createContents(double[] values, boolean logarithmicYAxis, String measurement, int step, File file) { Panel chartPanel = new Panel(); chartPanel.setLayout(new java.awt.GridLayout(1, 1)); JFreeChart chart = createChart("", "Sample", "Fitness", createSampleDataset(values, measurement, step), false);/*from ww w. j a v a2 s . c o m*/ ImageSaver.saveImage(chart.createBufferedImage(1000, 800), file.getParent(), "graph.png"); ChartPanel jFreeChartPanel = new ChartPanel(chart); chartPanel.add(jFreeChartPanel); return chartPanel; }
From source file:gobblin.publisher.BaseDataPublisherTest.java
private State buildDefaultState(int numBranches) throws IOException { State state = new State(); state.setProp(ConfigurationKeys.FORK_BRANCHES_KEY, numBranches); File tmpLocation = File.createTempFile("metadata", ""); tmpLocation.delete();//from ww w .j ava2 s. co m state.setProp(ConfigurationKeys.DATA_PUBLISHER_METADATA_OUTPUT_DIR, tmpLocation.getParent()); state.setProp(ConfigurationKeys.DATA_PUBLISHER_METADATA_OUTPUT_FILE, tmpLocation.getName()); return state; }
From source file:app.model.game.CoverUploadModel.java
public void uploadImage(HttpServletRequest req, Game g) throws FileUploadBase.SizeLimitExceededException, FileUploadException, SQLException, Exception { int width = 500; int height = 800; //Bild upload FileUpload upload = new FileUpload(2000 * 1024, 5000 * 1024, "C:/Users/Public/Arcade/Games/" + g.getGameID() + "/assets", "C:/Users/Public/Arcade/Games/" + g.getGameID() + "/tmp/"); File fileStatus; fileStatus = upload.uploadFile(req); File file = new File(fileStatus.getAbsolutePath()); BufferedImage img = ImageIO.read(file); if (img.getWidth() != width || img.getHeight() != height) { img = Scalr.resize(img, Scalr.Method.SPEED, Scalr.Mode.FIT_EXACT, 500, 800); }//from ww w. j a v a 2 s . com File destFile = new File(fileStatus.getParent() + "/" + g.getGameID() + ".jpg"); ImageIO.write(img, "jpg", destFile); g.updateState("coverupload", "complete"); String state = g.stateToJSON(); try (SQLHelper sql = new SQLHelper()) { sql.execNonQuery("UPDATE `games` SET editState='" + state + "' WHERE ID = " + g.getGameID()); } fileStatus.delete(); }
From source file:cppsensor.utils.UnitTestIOFilter.java
@Override public boolean accept(File file) { if (!file.isFile()) { return false; }// w w w. j a v a2 s .c o m String path = ""; try { path = file.getCanonicalPath(); } catch (IOException e) { log.error("Failed to get canonical path for file " + file, e); return false; } if (path.endsWith(".h")) { m_incDirs.add(file.getParent()); return true; } else if (path.endsWith(".cc") || path.endsWith(".c")) { return true; } else { return false; } }