Example #1
1
    @Override
    public void run() {
      while (true) {
        if (istWindows()) aktuell = holeLaufwerkeWindows();
        else aktuell = holeLaufwerkeUnix();

        if (initial.size() != aktuell.size()) {
          if (!initial.containsAll(aktuell)) {
            neuesLaufwerk = holePathVonNeuemLaufwerk(initial, aktuell);
            textArea.append("Neues Laufwerk endeckt:  " + neuesLaufwerk + System.lineSeparator());
            this.initial = (ArrayList<Path>) aktuell.clone();
            neuesLaufwerkDialog();

          } else {
            this.initial = (ArrayList<Path>) aktuell.clone();
            textArea.append("Laufwerk wurde entfernt" + System.lineSeparator());
          }
        }

        try {
          Thread.sleep(5000);
        } catch (InterruptedException e) {
          System.out.println("Laufwerksprüfung wird abgebrochen");
        }
      }
    }
Example #2
1
 private Path holePathVonNeuemLaufwerk(ArrayList<Path> initial, ArrayList<Path> aktuell) {
   ArrayList<Path> test, test1;
   test = (ArrayList<Path>) aktuell.clone();
   test1 = (ArrayList<Path>) initial.clone();
   test.removeAll(test1);
   return test.get(test.size() - 1);
 }
  public DependentLoaderImplementation cloneLoader(
      DependentLoader loader, String aditionalDependency) {
    DependentLoaderImplementation otherAsImplementation = (DependentLoaderImplementation) loader;

    DependentLoaderImplementation newLoader =
        new DependentLoaderImplementation(
            otherAsImplementation.artifact,
            loader.getURLs(),
            exposed,
            otherAsImplementation.parent);
    newLoader.dependencies = otherAsImplementation.dependencies;

    if (!"".equals(aditionalDependency)) {
      DependentLoaderImplementation dependency =
          enshureDependencyJarLoaded(otherAsImplementation.artifact, aditionalDependency);
      ArrayList<DependentLoaderImplementation> depList =
          new ArrayList<DependentLoaderImplementation>();
      for (DependentLoaderImplementation dependentLoaderImplementation : newLoader.dependencies) {
        depList.add(dependentLoaderImplementation);
      }
      depList.add(dependency);
      newLoader.setDependencies(depList.toArray(new DependentLoaderImplementation[depList.size()]));
    }
    visitLoader(newLoader);
    return newLoader;
  }
Example #4
0
 public Object tryArgument(String arg) throws Exception {
   try {
     ArrayList<Object> retval = new ArrayList<Object>();
     String[] values = arg.split(separator);
     if (values.length == 0) {
       throw new Exception("Invalid argument");
     }
     if (values.length == 1) {
       return handler.tryArgument(values[0]);
     }
     if (values.length > maxEntries) {
       throw new Exception(String.format("Cannot exceed %d entries", maxEntries));
     }
     for (String v : values) {
       Object param = handler.tryArgument(v);
       if (param == null) {
         throw new Exception(String.format("Invalid member of list: %s", v));
       }
       retval.add(param);
     }
     return retval;
   } catch (Exception e) {
     throw e;
   }
 }
Example #5
0
 private ArrayList<Path> holeLaufwerkeUnix() {
   ArrayList<Path> laufwerksRoot = new ArrayList<>();
   for (FileStore store : FileSystems.getDefault().getFileStores()) {
     if (store.name().contains("/dev/sd")) {
       laufwerksRoot.add(
           Paths.get(store.toString().substring(0, store.toString().indexOf(' '))));
     }
   }
   return laufwerksRoot;
 }
Example #6
0
    private ArrayList<Path> holeLaufwerkeWindows() {
      ArrayList<Path> laufwerksRoot = new ArrayList<>();

      Iterable<Path> rootDirectories = FileSystems.getDefault().getRootDirectories();

      for (Path path : rootDirectories) {
        laufwerksRoot.add(path.getRoot());
      }
      return laufwerksRoot;
    }
Example #7
0
 private boolean startLauncher(File dir) {
   try {
     Runtime rt = Runtime.getRuntime();
     ArrayList<String> command = new ArrayList<String>();
     command.add("java");
     command.add("-jar");
     command.add("Launcher.jar");
     String[] cmdarray = command.toArray(new String[command.size()]);
     Process proc = rt.exec(cmdarray, null, dir);
     return true;
   } catch (Exception ex) {
     System.err.println("Unable to start the Launcher program.\n" + ex.getMessage());
     return false;
   }
 }
  public DependentLoaderImplementation[] getLoaded(String filter) {
    DefaultArtifact asArtifact = new DefaultArtifact(filter);
    DependentLoaderImplementation theLoader = findOverride(asArtifact);
    if (theLoader != null) {
      DependentLoaderImplementation[] retVal = {theLoader};
      return retVal;
    }

    if (loaderMap.containsKey(filter)) {
      DependentLoaderImplementation[] retVal = {loaderMap.get(filter)};
      return retVal;
    }

    ArrayList<DependentLoaderImplementation> result = new ArrayList();
    for (String key : loaderMap.keySet()) {
      if (key.startsWith(filter)) {
        result.add(loaderMap.get(key));
      }
    }
    ;
    return Arrays.copyOf(result.toArray(), result.size(), DependentLoaderImplementation[].class);
  }
Example #9
0
  public PalindromeTest() {
    ArrayList<String> words = new ArrayList<String>();
    ArrayList<String> palis;

    try {
      for (String line : Files.readAllLines(Paths.get("com/jsanders/web2"))) {
        words.add(line);
      }
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }

    palis = Palindrome.palindromes(words);
    assertEquals(palis.size(), 161, 0.01);

    int shortest = Word.shortestLength(words);
    assertEquals(shortest, 1, 0.01);

    int longest = Word.longestLength(words);
    assertEquals(longest, 24, 0.01);

    ArrayList<String> shortestWords = Word.shortestWords(words);
    assertEquals(shortestWords.size(), 52, 0.01);

    ArrayList<String> longestWords = Word.longestWords(words);
    assertEquals(longestWords.size(), 5, 0.01);

    int totalWords = Word.totalWords(words);
    double avgLen = Word.averageLength(words);

    assertEquals(totalWords, 235886, 0.01);
    assertEquals(avgLen, 9.56, 0.01);

    ArrayList<Double> letterFreq = Word.letterFrequency(words);
    assertEquals(letterFreq.get(0), 0.087, 0.01);

    double properFreq = Word.properFrequency(words);
    assertEquals(properFreq, 0.106, 0.01);

    ArrayList<Integer> startFreq = Word.startFrequency(words);
    assertEquals(startFreq.get(0), 17096, 0.01);

    ArrayList<String> sameStartEnd = Word.startEndWords(words);
    assertEquals(sameStartEnd.size(), 11505, 0.01);

    try {
      PrintWriter f = new PrintWriter("short.txt");
      for (String w : shortestWords) f.println(w);
      f.close();

      f = new PrintWriter("long.txt");
      for (String w : longestWords) f.println(w);
      f.close();

      f = new PrintWriter("same.txt");
      for (String w : sameStartEnd) f.println(w);
      f.close();

      f = new PrintWriter("statistics.txt");
      f.println("avg word len: " + avgLen);
      f.println("freq of letters: " + letterFreq);
      f.println("freq of proper nouns/names: " + properFreq);
      f.println("words that start with each letter:: " + startFreq);

      f.close();
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }
  }
  /** Decode the buffer, returning an ACL */
  private static List<AclEntry> decode(long address, int n) {
    ArrayList<AclEntry> acl = new ArrayList<>(n);
    for (int i = 0; i < n; i++) {
      long offset = address + i * SIZEOF_ACE_T;

      int uid = unsafe.getInt(offset + OFFSETOF_UID);
      int mask = unsafe.getInt(offset + OFFSETOF_MASK);
      int flags = (int) unsafe.getShort(offset + OFFSETOF_FLAGS);
      int type = (int) unsafe.getShort(offset + OFFSETOF_TYPE);

      // map uid and flags to UserPrincipal
      UnixUserPrincipals.User who = null;
      if ((flags & ACE_OWNER) > 0) {
        who = UnixUserPrincipals.SPECIAL_OWNER;
      } else if ((flags & ACE_GROUP) > 0) {
        who = UnixUserPrincipals.SPECIAL_GROUP;
      } else if ((flags & ACE_EVERYONE) > 0) {
        who = UnixUserPrincipals.SPECIAL_EVERYONE;
      } else if ((flags & ACE_IDENTIFIER_GROUP) > 0) {
        who = UnixUserPrincipals.fromGid(uid);
      } else {
        who = UnixUserPrincipals.fromUid(uid);
      }

      AclEntryType aceType = null;
      switch (type) {
        case ACE_ACCESS_ALLOWED_ACE_TYPE:
          aceType = AclEntryType.ALLOW;
          break;
        case ACE_ACCESS_DENIED_ACE_TYPE:
          aceType = AclEntryType.DENY;
          break;
        case ACE_SYSTEM_AUDIT_ACE_TYPE:
          aceType = AclEntryType.AUDIT;
          break;
        case ACE_SYSTEM_ALARM_ACE_TYPE:
          aceType = AclEntryType.ALARM;
          break;
        default:
          assert false;
      }

      Set<AclEntryPermission> aceMask = EnumSet.noneOf(AclEntryPermission.class);
      if ((mask & ACE_READ_DATA) > 0) aceMask.add(AclEntryPermission.READ_DATA);
      if ((mask & ACE_WRITE_DATA) > 0) aceMask.add(AclEntryPermission.WRITE_DATA);
      if ((mask & ACE_APPEND_DATA) > 0) aceMask.add(AclEntryPermission.APPEND_DATA);
      if ((mask & ACE_READ_NAMED_ATTRS) > 0) aceMask.add(AclEntryPermission.READ_NAMED_ATTRS);
      if ((mask & ACE_WRITE_NAMED_ATTRS) > 0) aceMask.add(AclEntryPermission.WRITE_NAMED_ATTRS);
      if ((mask & ACE_EXECUTE) > 0) aceMask.add(AclEntryPermission.EXECUTE);
      if ((mask & ACE_DELETE_CHILD) > 0) aceMask.add(AclEntryPermission.DELETE_CHILD);
      if ((mask & ACE_READ_ATTRIBUTES) > 0) aceMask.add(AclEntryPermission.READ_ATTRIBUTES);
      if ((mask & ACE_WRITE_ATTRIBUTES) > 0) aceMask.add(AclEntryPermission.WRITE_ATTRIBUTES);
      if ((mask & ACE_DELETE) > 0) aceMask.add(AclEntryPermission.DELETE);
      if ((mask & ACE_READ_ACL) > 0) aceMask.add(AclEntryPermission.READ_ACL);
      if ((mask & ACE_WRITE_ACL) > 0) aceMask.add(AclEntryPermission.WRITE_ACL);
      if ((mask & ACE_WRITE_OWNER) > 0) aceMask.add(AclEntryPermission.WRITE_OWNER);
      if ((mask & ACE_SYNCHRONIZE) > 0) aceMask.add(AclEntryPermission.SYNCHRONIZE);

      Set<AclEntryFlag> aceFlags = EnumSet.noneOf(AclEntryFlag.class);
      if ((flags & ACE_FILE_INHERIT_ACE) > 0) aceFlags.add(AclEntryFlag.FILE_INHERIT);
      if ((flags & ACE_DIRECTORY_INHERIT_ACE) > 0) aceFlags.add(AclEntryFlag.DIRECTORY_INHERIT);
      if ((flags & ACE_NO_PROPAGATE_INHERIT_ACE) > 0)
        aceFlags.add(AclEntryFlag.NO_PROPAGATE_INHERIT);
      if ((flags & ACE_INHERIT_ONLY_ACE) > 0) aceFlags.add(AclEntryFlag.INHERIT_ONLY);

      // build the ACL entry and add it to the list
      AclEntry ace =
          AclEntry.newBuilder()
              .setType(aceType)
              .setPrincipal(who)
              .setPermissions(aceMask)
              .setFlags(aceFlags)
              .build();
      acl.add(ace);
    }

    return acl;
  }