List of usage examples for java.util EnumSet of
public static <E extends Enum<E>> EnumSet<E> of(E e)
From source file:ch.cyberduck.core.s3.S3ObjectListService.java
public AttributedList<Path> list(final Path directory, final ListProgressListener listener, final String delimiter, final int chunksize) throws BackgroundException { try {/*w w w.j av a 2 s .c o m*/ final String prefix = this.createPrefix(directory); // If this optional, Unicode string parameter is included with your request, // then keys that contain the same string between the prefix and the first // occurrence of the delimiter will be rolled up into a single result // element in the CommonPrefixes collection. These rolled-up keys are // not returned elsewhere in the response. final Path bucket = containerService.getContainer(directory); final AttributedList<Path> children = new AttributedList<Path>(); // Null if listing is complete String priorLastKey = null; do { // Read directory listing in chunks. List results are always returned // in lexicographic (alphabetical) order. final StorageObjectsChunk chunk = session.getClient().listObjectsChunked( PathNormalizer.name(URIEncoder.encode(bucket.getName())), prefix, delimiter, chunksize, priorLastKey); final StorageObject[] objects = chunk.getObjects(); for (StorageObject object : objects) { final String key = PathNormalizer.normalize(object.getKey()); if (String.valueOf(Path.DELIMITER).equals(key)) { log.warn(String.format("Skipping prefix %s", key)); continue; } if (new Path(bucket, key, EnumSet.of(Path.Type.directory)).equals(directory)) { continue; } final EnumSet<AbstractPath.Type> types = object.getKey() .endsWith(String.valueOf(Path.DELIMITER)) ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file); final Path file; final PathAttributes attributes = this.attributes.convert(object); // Copy bucket location attributes.setRegion(bucket.attributes().getRegion()); if (null == delimiter) { file = new Path( String.format("%s%s%s", bucket.getAbsolute(), String.valueOf(Path.DELIMITER), key), types, attributes); } else { file = new Path(directory, PathNormalizer.name(key), types, attributes); } children.add(file); } final String[] prefixes = chunk.getCommonPrefixes(); for (String common : prefixes) { if (String.valueOf(Path.DELIMITER).equals(common)) { log.warn(String.format("Skipping prefix %s", common)); continue; } final String key = PathNormalizer.normalize(common); if (new Path(bucket, key, EnumSet.of(Path.Type.directory)).equals(directory)) { continue; } final Path file; final PathAttributes attributes = new PathAttributes(); if (null == delimiter) { file = new Path( String.format("%s%s%s", bucket.getAbsolute(), String.valueOf(Path.DELIMITER), key), EnumSet.of(Path.Type.directory, Path.Type.placeholder), attributes); } else { file = new Path(directory, PathNormalizer.name(key), EnumSet.of(Path.Type.directory, Path.Type.placeholder), attributes); } attributes.setRegion(bucket.attributes().getRegion()); children.add(file); } priorLastKey = chunk.getPriorLastKey(); listener.chunk(directory, children); } while (priorLastKey != null); return children; } catch (ServiceException e) { throw new S3ExceptionMappingService().map("Listing directory {0} failed", e, directory); } }
From source file:io.fabric8.apiman.Fabric8ManagerApiMicroService.java
@Override protected void addAuthFilter(ServletContextHandler apiManServer) { apiManServer.addFilter(BootstrapFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); apiManServer.addFilter(BearerTokenFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); apiManServer.addFilter(Kubernetes2ApimanFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); }
From source file:ch.cyberduck.core.manta.AbstractMantaTest.java
protected Path randomDirectory() { return new Path(testPathPrefix, UUID.randomUUID().toString(), EnumSet.of(Type.directory)); }
From source file:org.cloudfoundry.practical.demo.web.controller.CompilerController.java
private boolean compile(Folders folders, Writer out) throws IOException { JavaFileManager standardFileManager = this.compiler.getStandardFileManager(null, null, null); ResourceJavaFileManager fileManager = new ResourceJavaFileManager(standardFileManager); fileManager.setLocation(StandardLocation.SOURCE_PATH, folders.getSource()); fileManager.setLocation(StandardLocation.CLASS_OUTPUT, folders.getOutput()); fileManager.setLocation(StandardLocation.CLASS_PATH, folders.getLibJars()); Iterable<? extends JavaFileObject> units = fileManager.list(StandardLocation.SOURCE_PATH, "", EnumSet.of(Kind.SOURCE), true); CompilationTask task = this.compiler.getTask(out, fileManager, null, COMPILER_OPTIONS, null, units); return task.call(); }
From source file:io.lavagna.service.SearchServiceTest.java
@Before public void prepare() { userRepository.createUser("test", "test", null, null, true); userRepository.createUser("test", "test-no-access", null, null, true); user = userRepository.findUserByName("test", "test"); userWithNoAccess = userRepository.findUserByName("test", "test-no-access"); Role r = new Role("TEST"); permissionService.createRole(r);//from w w w . j ava 2 s.c o m permissionService.updatePermissionsToRole(r, EnumSet.of(Permission.READ)); permissionService.assignRolesToUsers(Collections.singletonMap(r, Collections.singleton(user.getId()))); userWithPermissions = new UserWithPermission(user, permissionService.findBasePermissionByUserId(user.getId()), Collections.<String, Set<Permission>>emptyMap(), Collections.<Integer, Set<Permission>>emptyMap()); userWithNoAccessPermission = new UserWithPermission(userWithNoAccess, permissionService.findBasePermissionByUserId(userWithNoAccess.getId()), Collections.<String, Set<Permission>>emptyMap(), Collections.<Integer, Set<Permission>>emptyMap()); project = projectService.create("test search", "TEST-SRC", "desc"); board = boardRepository.createNewBoard("TEST-SEARCH", "TEST-SRC", "desc", project.getId()); List<BoardColumnDefinition> columnDefinitions = projectService .findColumnDefinitionsByProjectId(project.getId()); for (BoardColumnDefinition bcd : columnDefinitions) { if (bcd.getValue() == ColumnDefinition.OPEN) { column = boardColumnRepository.addColumnToBoard("test", bcd.getId(), BoardColumnLocation.BOARD, board.getId()); } else if (bcd.getValue() == ColumnDefinition.CLOSED) { closedColumn = boardColumnRepository.addColumnToBoard("test", bcd.getId(), BoardColumnLocation.BOARD, board.getId()); } } }
From source file:com.netflix.genie.common.internal.dto.JobDirectoryManifest.java
/** * Create a manifest from the given job directory. * * @param directory The job directory to create a manifest from * @param calculateFileChecksums Whether or not to calculate checksums for each file added to the manifest * @throws IOException If there is an error reading the directory *///from w ww . j a v a 2s . c o m public JobDirectoryManifest(final Path directory, final boolean calculateFileChecksums) throws IOException { // Walk the directory final ImmutableMap.Builder<String, ManifestEntry> builder = ImmutableMap.builder(); final ManifestVisitor manifestVisitor = new ManifestVisitor(directory, builder, calculateFileChecksums); final EnumSet<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS); Files.walkFileTree(directory, options, Integer.MAX_VALUE, manifestVisitor); this.entries = builder.build(); final ImmutableSet.Builder<ManifestEntry> filesBuilder = ImmutableSet.builder(); final ImmutableSet.Builder<ManifestEntry> directoriesBuilder = ImmutableSet.builder(); long sizeOfFiles = 0L; for (final ManifestEntry entry : this.entries.values()) { if (entry.isDirectory()) { directoriesBuilder.add(entry); } else { filesBuilder.add(entry); sizeOfFiles += entry.getSize(); } } this.totalSizeOfFiles = sizeOfFiles; this.directories = directoriesBuilder.build(); this.files = filesBuilder.build(); this.numDirectories = this.directories.size(); this.numFiles = this.files.size(); }
From source file:com.cloudera.ByteBufferRecordReader.java
private void initialize(Configuration job, long splitStart, long splitLength, Path file) throws IOException { start = splitStart;/*from w w w .jav a 2s .c om*/ end = start + splitLength; pos = start; // open the file and seek to the start of the split final FileSystem fs = file.getFileSystem(job); fileIn = fs.open(file); this.readStats = new ReadStatistics(); this.bufferPool = new ElasticByteBufferPool(); boolean skipChecksums = job.getBoolean("bytecount.skipChecksums", false); this.readOption = skipChecksums ? EnumSet.of(ReadOption.SKIP_CHECKSUMS) : EnumSet.noneOf(ReadOption.class); CompressionCodec codec = new CompressionCodecFactory(job).getCodec(file); if (null != codec) { isCompressedInput = true; decompressor = CodecPool.getDecompressor(codec); CompressionInputStream cIn = codec.createInputStream(fileIn, decompressor); filePosition = cIn; inputStream = cIn; LOG.info("Compressed input; cannot compute number of records in the split"); } else { fileIn.seek(start); filePosition = fileIn; inputStream = fileIn; LOG.info("Split pos = " + start + " length " + splitLength); } }
From source file:magicdeckmanager.card.Card.java
private EnumSet<Color> calculateCardColor() { EnumSet<Color> result = EnumSet.of(Color.Colorless); List<ManaPart> cost = manaCost.getCost(); extractColorsFromManaCost(cost, result); return result; }
From source file:burstcoin.jminer.core.reader.task.ReaderLoadDriveTask.java
private boolean load(PlotFile plotFile) { try (SeekableByteChannel sbc = Files.newByteChannel(plotFile.getFilePath(), EnumSet.of(StandardOpenOption.READ))) { long currentScoopPosition = scoopNumber * plotFile.getStaggeramt() * MiningPlot.SCOOP_SIZE; long partSize = plotFile.getStaggeramt() / plotFile.getNumberOfParts(); ByteBuffer partBuffer = ByteBuffer.allocate((int) (partSize * MiningPlot.SCOOP_SIZE)); // optimized plotFiles only have one chunk! for (int chunkNumber = 0; chunkNumber < plotFile.getNumberOfChunks(); chunkNumber++) { long currentChunkPosition = chunkNumber * plotFile.getStaggeramt() * MiningPlot.PLOT_SIZE; sbc.position(currentScoopPosition + currentChunkPosition); for (int partNumber = 0; partNumber < plotFile.getNumberOfParts(); partNumber++) { sbc.read(partBuffer);/*from w w w . j a v a2 s . c om*/ if (Reader.blockNumber != blockNumber) { LOG.trace("loadDriveThread stopped!"); partBuffer.clear(); sbc.close(); return true; } else { long chunkPartStartNonce = plotFile.getStartnonce() + (chunkNumber * plotFile.getStaggeramt()) + (partNumber * partSize); final byte[] scoops = partBuffer.array(); publisher.publishEvent(new ReaderLoadedPartEvent(blockNumber, scoops, chunkPartStartNonce)); } partBuffer.clear(); } } sbc.close(); } catch (NoSuchFileException exception) { LOG.error("File not found ... please restart to rescan plot-files, maybe set rescan to 'true': " + exception.getMessage()); } catch (ClosedByInterruptException e) { // we reach this, if we do not wait for task on shutdown - ByteChannel closed by thread interruption LOG.trace("reader stopped cause of new block ..."); } catch (IOException e) { LOG.error("IOException: " + e.getMessage()); } return false; }
From source file:net.mozq.picto.core.ProcessCore.java
public static void findFiles(ProcessCondition processCondition, Consumer<ProcessData> processDataSetter, BooleanSupplier processStopper) throws IOException { Set<FileVisitOption> fileVisitOptionSet; if (processCondition.isFollowLinks()) { fileVisitOptionSet = EnumSet.of(FileVisitOption.FOLLOW_LINKS); } else {/* w ww. j a v a 2s . co m*/ fileVisitOptionSet = Collections.emptySet(); } Files.walkFileTree(processCondition.getSrcRootPath(), fileVisitOptionSet, processCondition.getDept(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (processStopper.getAsBoolean()) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.SKIP_SUBTREE; } if (processStopper.getAsBoolean()) { return FileVisitResult.TERMINATE; } if (!processCondition.getPathFilter().accept(file, attrs)) { return FileVisitResult.SKIP_SUBTREE; } Path rootRelativeSubPath = processCondition.getSrcRootPath().relativize(file.getParent()); ImageMetadata imageMetadata = getImageMetadata(file); Date baseDate; if (processCondition.isChangeFileCreationDate() || processCondition.isChangeFileModifiedDate() || processCondition.isChangeFileAccessDate() || processCondition.isChangeExifDate()) { baseDate = getBaseDate(processCondition, file, attrs, imageMetadata); } else { baseDate = null; } String destSubPathname = processCondition.getDestSubPathFormat().format(varName -> { try { switch (varName) { case "Now": return new Date(); case "ParentSubPath": return rootRelativeSubPath.toString(); case "FileName": return file.getFileName().toString(); case "BaseName": return FileUtilz.getBaseName(file.getFileName().toString()); case "Extension": return FileUtilz.getExt(file.getFileName().toString()); case "Size": return Long.valueOf(Files.size(file)); case "CreationDate": return (processCondition.isChangeFileCreationDate()) ? baseDate : new Date(attrs.creationTime().toMillis()); case "ModifiedDate": return (processCondition.isChangeFileModifiedDate()) ? baseDate : new Date(attrs.lastModifiedTime().toMillis()); case "AccessDate": return (processCondition.isChangeFileAccessDate()) ? baseDate : new Date(attrs.lastAccessTime().toMillis()); case "PhotoTakenDate": return (processCondition.isChangeExifDate()) ? baseDate : getPhotoTakenDate(file, imageMetadata); case "Width": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_WIDTH); case "Height": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_LENGTH); case "FNumber": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FNUMBER); case "Aperture": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_APERTURE_VALUE); case "MaxAperture": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_MAX_APERTURE_VALUE); case "ISO": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_ISO); case "FocalLength": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FOCAL_LENGTH); // ? case "FocalLength35mm": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FOCAL_LENGTH_IN_35MM_FORMAT); case "ShutterSpeed": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE); case "Exposure": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE); // case "ExposureTime": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_TIME); // case "ExposureMode": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_MODE); case "ExposureProgram": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_PROGRAM); case "Brightness": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE); case "WhiteBalance": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_WHITE_BALANCE_1); case "LightSource": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_LIGHT_SOURCE); case "Lens": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS); case "LensMake": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MAKE); case "LensModel": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MODEL); case "LensSerialNumber": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_SERIAL_NUMBER); case "Make": return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MAKE); case "Model": return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MODEL); case "SerialNumber": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_SERIAL_NUMBER); case "Software": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_SOFTWARE); case "ProcessingSoftware": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_PROCESSING_SOFTWARE); case "OwnerName": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_OWNER_NAME); case "CameraOwnerName": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_CAMERA_OWNER_NAME); case "GPSLat": return getEXIFGpsLat(imageMetadata); case "GPSLatDeg": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 0); case "GPSLatMin": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 1); case "GPSLatSec": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 2); case "GPSLatRef": return getEXIFStringValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); case "GPSLon": return getEXIFGpsLon(imageMetadata); case "GPSLonDeg": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 0); case "GPSLonMin": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 1); case "GPSLonSec": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 2); case "GPSLonRef": return getEXIFStringValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); case "GPSAlt": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE); case "GPSAltRef": return getEXIFIntValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE_REF); default: throw new PictoInvalidDestinationPathException(Messages .getString("message.warn.invalid.destSubPath.varName", varName)); } } catch (PictoException e) { throw e; } catch (Exception e) { throw new PictoInvalidDestinationPathException( Messages.getString("message.warn.invalid.destSubPath.pattern"), e); } }); Path destSubPath = processCondition.getDestRootPath().resolve(destSubPathname).normalize(); if (!destSubPath.startsWith(processCondition.getDestRootPath())) { throw new PictoInvalidDestinationPathException( Messages.getString("message.warn.invalid.destination.path", destSubPath)); } ProcessData processData = new ProcessData(); processData.setSrcPath(file); processData.setSrcFileAttributes(attrs); processData.setDestPath(destSubPath); processData.setBaseDate(baseDate); processDataSetter.accept(processData); return FileVisitResult.CONTINUE; } }); }