All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.objectos.io.IoImplJava7 Maven / Gradle / Ivy

/*
 * Copyright (C) 2011-2021 Objectos Software LTDA.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package br.com.objectos.io;

import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;

import br.com.objectos.lang.Lang;
import br.com.objectos.lang.OperatingSystem.Family;
import br.com.objectos.multirelease.Singleton;
import java.nio.file.Path;
import java.nio.file.WatchEvent;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.EnumSet;
import java.util.Set;

final class IoImplJava7 extends Io.Impl {

  static final Family _OS_FAMILY = Lang.getOperatingSystem().getFamily();

  static final FileAttribute[] EMPTY_FILE_ATTRIBUTES = new FileAttribute[0];

  @Singleton.Field
  static final Io.Impl INSTANCE = new IoImplJava7();

  private static final WatchEvent.Kind[] EVENTS = new WatchEvent.Kind[] {
      ENTRY_CREATE,
      ENTRY_DELETE,
      ENTRY_MODIFY
  };

  static WatchEvent.Kind[] getEvents(Set set) {
    WatchEvent.Kind[] events;
    events = new WatchEvent.Kind[set.size()];

    int i = 0;

    for (EventKind kind : set) {
      int ordinal;
      ordinal = kind.ordinal();

      events[i++] = EVENTS[ordinal];
    }

    return events;
  }

  static Path getPath(FsObject o) {
    return (Path) o.getDelegate();
  }

  static FileAttribute[] single(PosixFilePermission p) {
    EnumSet set;
    set = EnumSet.of(p);

    FileAttribute> a;
    a = PosixFilePermissions.asFileAttribute(set);

    return new FileAttribute[] {a};
  }

  @Override
  public final PosixFileModeOption ownerExecutable() {
    return PosixFileModeOptionJava7.OWNER_EXECUTABLE;
  }

  @Override
  public final PosixFileModeOption ownerReadable() {
    return PosixFileModeOptionJava7.OWNER_READABLE;
  }

  @Override
  public final PosixFileModeOption ownerWritable() {
    return PosixFileModeOptionJava7.OWNER_WRITABLE;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy