List of usage examples for java.nio.file Files isWritable
public static boolean isWritable(Path path)
From source file:se.trixon.mapollage.Operation.java
@Override public void run() { if (!Files.isWritable(mDestinationFile.getParentFile().toPath())) { mListener.onOperationLog(String.format(mBundle.getString("insufficient_privileges"), mDestinationFile.getAbsolutePath())); Thread.currentThread().interrupt(); mListener.onOperationInterrupted(); return;/*from w w w. j av a2s. co m*/ } mStartTime = System.currentTimeMillis(); Date date = new Date(mStartTime); SimpleDateFormat dateFormat = new SimpleDateFormat(); mListener.onOperationStarted(); mListener.onOperationLog(dateFormat.format(date)); String status; mRootFolder = mDocument.createAndAddFolder().withName(getSafeXmlString(mProfileFolder.getRootName())) .withOpen(true); String href = "<a href=\"https://trixon.se/mapollage/\">Mapollage</a>"; String description = String.format("<p>%s %s, %s</p>%s", Dict.MADE_WITH.toString(), href, dateFormat.format(date), mProfileFolder.getRootDescription().replaceAll("\\n", "<br />")); mRootFolder.setDescription(getSafeXmlString(description)); mListener.onOperationProcessingStarted(); try { mInterrupted = !generateFileList(); } catch (IOException ex) { logError(ex.getMessage()); } if (!mInterrupted && !mFiles.isEmpty()) { if (isUsingThumbnails()) { mThumbsDir = new File(mDestinationFile.getParent() + String.format("/%s-thumbnails", FilenameUtils.getBaseName(mDestinationFile.getAbsolutePath()))); try { FileUtils.forceMkdir(mThumbsDir); } catch (IOException ex) { logError(String.format("E000 %s", ex.getMessage())); } } mListener.onOperationLog(String.format(mBundle.getString("found_count"), mFiles.size())); mListener.onOperationLog(""); int progress = 0; for (File file : mFiles) { mListener.onOperationProgress(file.getAbsolutePath()); mListener.onOperationProgress(++progress, mFiles.size()); try { addPhoto(file); } catch (ImageProcessingException ex) { logError(String.format("E000 %s", ex.getMessage())); } catch (IOException ex) { logError(String.format("E000 %s", file.getAbsolutePath())); } if (Thread.interrupted()) { mInterrupted = true; break; } } if (mProfilePath.isDrawPath() && mLineNodes.size() > 1) { addPath(); } } if (mInterrupted) { status = Dict.TASK_ABORTED.toString(); mListener.onOperationLog("\n" + status); mListener.onOperationInterrupted(); } else if (!mFiles.isEmpty()) { if (mProfilePath.isDrawPolygon()) { addPolygons(); } saveToFile(); mProfile.setLastRun(System.currentTimeMillis()); } if (mNumOfErrors > 0) { logError(mBundle.getString("error_description")); } }
From source file:se.trixon.mapollage.Operation.java
private void addPhoto(File file) throws ImageProcessingException, IOException { mPhotoInfo = new PhotoInfo(file, mProfileSource.isIncludeNullCoordinate()); try {// www . j a va 2 s . c om mPhotoInfo.init(); } catch (ImageProcessingException | IOException e) { if (mPhotoInfo.hasExif()) { mNumOfExif++; } throw e; } boolean hasLocation = false; if (mPhotoInfo.hasExif()) { mNumOfExif++; hasLocation = mPhotoInfo.hasGps() && !mPhotoInfo.isZeroCoordinate(); if (hasLocation) { mNumOfGps++; } } else { throw new ImageProcessingException(String.format("E010 %s", file.getAbsolutePath())); } Date exifDate = mPhotoInfo.getDate(); if (hasLocation && mProfilePath.isDrawPath()) { mLineNodes.add(new LineNode(exifDate, mPhotoInfo.getLat(), mPhotoInfo.getLon())); } if (hasLocation || mProfileSource.isIncludeNullCoordinate()) { Folder folder = getFolder(file, exifDate); String imageId = String.format("%08x", FileUtils.checksumCRC32(file)); String styleNormalId = String.format("s_%s", imageId); String styleHighlightId = String.format("s_%s_hl", imageId); String styleMapId = String.format("m_%s", imageId); Style normalStyle = mDocument.createAndAddStyle().withId(styleNormalId); IconStyle normalIconStyle = normalStyle.createAndSetIconStyle().withScale(1.0); Style highlightStyle = mDocument.createAndAddStyle().withBalloonStyle(mBalloonStyle) .withId(styleHighlightId); IconStyle highlightIconStyle = highlightStyle.createAndSetIconStyle().withScale(1.1); if (mProfilePlacemark.isSymbolAsPhoto()) { Icon icon = KmlFactory.createIcon() .withHref(String.format("%s/%s.jpg", mThumbsDir.getName(), imageId)); normalIconStyle.setIcon(icon); normalIconStyle.setScale(mProfilePlacemark.getScale()); double highlightZoom = mProfilePlacemark.getZoom() * mProfilePlacemark.getScale(); highlightIconStyle.setIcon(icon); highlightIconStyle.setScale(highlightZoom); } if (isUsingThumbnails()) { File thumbFile = new File(mThumbsDir, imageId + ".jpg"); mFileThumbMap.put(file, thumbFile); if (Files.isWritable(thumbFile.getParentFile().toPath())) { mPhotoInfo.createThumbnail(thumbFile); } else { mListener.onOperationLog(String.format(mBundle.getString("insufficient_privileges"), mDestinationFile.getAbsolutePath())); Thread.currentThread().interrupt(); return; } } mDocument.createAndAddStyleMap().withId(styleMapId) .addToPair(KmlFactory.createPair().withKey(StyleState.NORMAL).withStyleUrl("#" + styleNormalId)) .addToPair(KmlFactory.createPair().withKey(StyleState.HIGHLIGHT) .withStyleUrl("#" + styleHighlightId)); Placemark placemark = KmlFactory.createPlacemark() .withName(getSafeXmlString(getPlacemarkName(file, exifDate))).withOpen(Boolean.TRUE) .withStyleUrl("#" + styleMapId); String desc = getPlacemarkDescription(file, mPhotoInfo, exifDate); if (!StringUtils.isBlank(desc)) { placemark.setDescription(desc); } placemark.createAndSetPoint().addToCoordinates(mPhotoInfo.getLon(), mPhotoInfo.getLat(), 0F); if (mProfilePlacemark.isTimestamp()) { TimeStamp timeStamp = KmlFactory.createTimeStamp(); timeStamp.setWhen(mTimeStampDateFormat.format(exifDate)); placemark.setTimePrimitive(timeStamp); } folder.addToFeature(placemark); mNumOfPlacemarks++; } mListener.onOperationLog(file.getAbsolutePath()); }
From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalUtils.java
public static void checkPrivilegesOnDirectory(Path location) { log.debug("Check the Location {}", location); Validate.isTrue(Files.exists(location)); Validate.isTrue(Files.isDirectory(location)); Validate.isTrue(Files.isReadable(location)); // List Files within Directory Validate.isTrue(Files.isExecutable(location)); // can change into Directory Validate.isTrue(Files.isWritable(location)); // can create or delete Files within Directory }
From source file:uk.ac.ebi.interpro.scan.jms.main.AbstractI5Runner.java
/** * Check if a specified path exists and is readable. * @param path The full file or directory path under review (e.g. "/tmp/test_proteins.fasta") * @param checkParent Do we just check the parent path? (e.g. "/tmp") * @param checkWriteable Should we also check that the path or parent path can be written to? * @param option The user input {@link I5Option} this path relates to (or null if not applicable) * @return True if the checks succeed, otherwise false (although the system will exit if a {@link I5Option} check fails) *///from ww w . j a v a 2 s .c om protected static boolean checkPathExistence(final String path, final boolean checkParent, final boolean checkWriteable, final I5Option option) { String pathToCheck = path; if (checkParent) { pathToCheck = path.substring(0, path.lastIndexOf(File.separator)); } Path p = FileSystems.getDefault().getPath(pathToCheck); boolean exists = Files.isReadable(p); if (option != null && !exists) { System.out.println("For the (-" + option.getShortOpt() + ") option you specified a location which doesn't exist or is not readable:"); System.out.println(path); System.exit(2); } if (exists && checkWriteable) { boolean writable = Files.isWritable(p); if (option != null && !writable) { System.out.println("For the (-" + option.getShortOpt() + ") option you specified a location which is not writable:"); System.out.println(path); System.exit(2); } return writable; } return exists; }