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
  public double saveBinaryFileWithBuffer() {
    double time = System.nanoTime();
    File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\binFileWithBuffer.bin");
    DataOutputStream outPut = null;
    DataInputStream inPut = null;
    FileOutputStream fileOut = null;
    FileInputStream fileIn = null;
    BufferedInputStream buffInput = null;
    BufferedOutputStream buffOut = null;
    try {
      fileOut = new FileOutputStream(file);
      buffOut = new BufferedOutputStream(fileOut);
      outPut = new DataOutputStream(buffOut);
      for (Edge e : edges) {
        outPut.writeDouble(e.X1);
        outPut.writeDouble(e.Y1);
        outPut.writeDouble(e.X2);
        outPut.writeDouble(e.Y2);
        outPut.writeDouble(e.color.getRed());
        outPut.writeDouble(e.color.getGreen());
        outPut.writeDouble(e.color.getBlue());
        outPut.flush();
      }
      outPut.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    edges.clear();
    // Now read every edge from the file and draw it.
    try {
      fileIn = new FileInputStream(file);
      buffInput = new BufferedInputStream(fileIn);
      inPut = new DataInputStream(buffInput);

      if (inPut.available() > 0) {
        while (inPut.available() > 0) {
          double X1 = inPut.readDouble();
          double Y1 = inPut.readDouble();
          double X2 = inPut.readDouble();
          double Y2 = inPut.readDouble();
          double red = inPut.readDouble();
          double green = inPut.readDouble();
          double blue = inPut.readDouble();

          Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1));
          drawEdge(e);
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return System.nanoTime() - time;
  }
 /**
  * Tries to lock all local shards for the given index. If any of the shard locks can't be acquired
  * an {@link LockObtainFailedException} is thrown and all previously acquired locks are released.
  *
  * @param index the index to lock shards for
  * @param lockTimeoutMS how long to wait for acquiring the indices shard locks
  * @return the {@link ShardLock} instances for this index.
  * @throws IOException if an IOException occurs.
  */
 public List<ShardLock> lockAllForIndex(
     Index index, @IndexSettings Settings settings, long lockTimeoutMS) throws IOException {
   final Integer numShards = settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, null);
   if (numShards == null || numShards <= 0) {
     throw new IllegalArgumentException("settings must contain a non-null > 0 number of shards");
   }
   logger.trace("locking all shards for index {} - [{}]", index, numShards);
   List<ShardLock> allLocks = new ArrayList<>(numShards);
   boolean success = false;
   long startTimeNS = System.nanoTime();
   try {
     for (int i = 0; i < numShards; i++) {
       long timeoutLeftMS =
           Math.max(0, lockTimeoutMS - TimeValue.nsecToMSec((System.nanoTime() - startTimeNS)));
       allLocks.add(shardLock(new ShardId(index, i), timeoutLeftMS));
     }
     success = true;
   } finally {
     if (success == false) {
       logger.trace("unable to lock all shards for index {}", index);
       IOUtils.closeWhileHandlingException(allLocks);
     }
   }
   return allLocks;
 }
  @Override
  public void run(String... args) throws Exception {
    CommandLine line = this.commandLineParser.parse(this.options, args);
    String[] remainingArgs = line.getArgs();

    if (remainingArgs.length < 3 && !line.hasOption("file")
        || remainingArgs.length < 1 && line.hasOption("file")) {
      helpFormatter.printHelp("xmergel [OPTION] [file1 file2 ...] [result_file]", this.options);
      System.exit(1);
    }
    if (line.hasOption("debug")) {
      this.isDebug = true;
    }
    List<Path> filesToCombine = this.getPathsFromArgs(remainingArgs);
    if (line.hasOption("file")) {
      System.out.println("Finding files...");
      filesToCombine = this.getPathsFromFile(line.getOptionValue("file"), filesToCombine);
    }
    String output = remainingArgs[remainingArgs.length - 1];
    System.out.println("Merging files...");
    try {
      this.xmergel.setResultFile(output);
      this.xmergel.combine(filesToCombine);
    } catch (Exception e) {
      System.out.println("Error: " + e.getMessage());
      if (this.isDebug) {
        e.printStackTrace();
      }
      System.exit(1);
    }
    File fileOutput = Paths.get(output).toFile();
    System.out.println("Files have been merged in '" + fileOutput.getAbsolutePath() + "'.");
  }
Example #5
0
  void test(String[] opts, String className) throws Exception {
    count++;
    System.err.println("Test " + count + " " + Arrays.asList(opts) + " " + className);
    Path testSrcDir = Paths.get(System.getProperty("test.src"));
    Path testClassesDir = Paths.get(System.getProperty("test.classes"));
    Path classes = Paths.get("classes." + count);
    classes.createDirectory();

    Context ctx = new Context();
    PathFileManager fm = new JavacPathFileManager(ctx, true, null);
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    List<String> options = new ArrayList<String>();
    options.addAll(Arrays.asList(opts));
    options.addAll(Arrays.asList("-verbose", "-XDverboseCompilePolicy", "-d", classes.toString()));
    Iterable<? extends JavaFileObject> compilationUnits =
        fm.getJavaFileObjects(testSrcDir.resolve(className + ".java"));
    StringWriter sw = new StringWriter();
    PrintWriter out = new PrintWriter(sw);
    JavaCompiler.CompilationTask t =
        compiler.getTask(out, fm, null, options, null, compilationUnits);
    boolean ok = t.call();
    System.err.println(sw.toString());
    if (!ok) {
      throw new Exception("compilation failed");
    }

    File expect = new File("classes." + count + "/" + className + ".class");
    if (!expect.exists()) throw new Exception("expected file not found: " + expect);
    long expectedSize = new File(testClassesDir.toString(), className + ".class").length();
    long actualSize = expect.length();
    if (expectedSize != actualSize)
      throw new Exception("wrong size found: " + actualSize + "; expected: " + expectedSize);
  }
Example #6
0
 static {
   logger.info("Loading DLL");
   try {
     System.loadLibrary(JINPUT);
     System.loadLibrary(LWJGL);
     System.loadLibrary(OPENAL);
     logger.info("DLL is loaded from memory");
   } catch (UnsatisfiedLinkError e) {
     loadFromJar();
   }
 }
Example #7
0
  public double saveBinaryFileNoBuffer() throws IOException {
    double time = System.nanoTime();
    File file =
        new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\binFileWithoutBuffer.bin");
    FileChannel fileChannel = null;
    MappedByteBuffer map = null;
    int counter = 0;
    try {
      //            fileOut = new FileOutputStream(file);
      //            outPut = new DataOutputStream(fileOut);
      fileChannel = new RandomAccessFile(file, "rw").getChannel();
      map = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 4096 * 128 * 128);
      counter = edges.size();
      for (Edge e : edges) {
        map.putDouble(e.X1);
        map.putDouble(e.Y1);
        map.putDouble(e.X2);
        map.putDouble(e.Y2);
        map.putDouble(e.color.getRed());
        map.putDouble(e.color.getGreen());
        map.putDouble(e.color.getBlue());
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    edges.clear();
    map.position(0);
    // Now read every edge from the file and draw it.
    try {
      //            fileIn = new FileInputStream(file);
      //            inPut = new DataInputStream(fileIn);
      fileChannel = new RandomAccessFile(file, "r").getChannel();
      map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 4096 * 128 * 128);
      for (int i = 0; i <= counter; i++) {
        double X1 = map.getDouble();
        double Y1 = map.getDouble();
        double X2 = map.getDouble();
        double Y2 = map.getDouble();
        double red = map.getDouble();
        double green = map.getDouble();
        double blue = map.getDouble();

        Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1));
        drawEdge(e);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return System.nanoTime() - time;
  }
  public static void main(String[] args) throws IOException {
    System.out.println("Input Stream:");
    long start = System.currentTimeMillis();
    Path filename = Paths.get(args[0]);
    long crcValue = checksumInputStream(filename);
    long end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Buffered Input Stream:");
    start = System.currentTimeMillis();
    crcValue = checksumBufferedInputStream(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Random Access File:");
    start = System.currentTimeMillis();
    crcValue = checksumRandomAccessFile(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");

    System.out.println("Mapped File:");
    start = System.currentTimeMillis();
    crcValue = checksumMappedFile(filename);
    end = System.currentTimeMillis();
    System.out.println(Long.toHexString(crcValue));
    System.out.println((end - start) + " milliseconds");
  }
Example #9
0
  private void updateLinuxServiceInstaller() {
    try {
      File dir = new File(directory, "CTP");
      if (suppressFirstPathElement) dir = dir.getParentFile();
      Properties props = new Properties();
      String ctpHome = dir.getAbsolutePath();
      cp.appendln(Color.black, "...CTP_HOME: " + ctpHome);
      ctpHome = ctpHome.replaceAll("\\\\", "\\\\\\\\");
      props.put("CTP_HOME", ctpHome);
      File javaHome = new File(System.getProperty("java.home"));
      String javaBin = (new File(javaHome, "bin")).getAbsolutePath();
      cp.appendln(Color.black, "...JAVA_BIN: " + javaBin);
      javaBin = javaBin.replaceAll("\\\\", "\\\\\\\\");
      props.put("JAVA_BIN", javaBin);

      File linux = new File(dir, "linux");
      File install = new File(linux, "ctpService-ubuntu.sh");
      cp.appendln(Color.black, "Linux service installer:");
      cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
      String bat = getFileText(install);
      bat = replace(bat, props); // do the substitutions
      bat = bat.replace("\r", "");
      setFileText(install, bat);

      // If this is an ISN installation, put the script in the correct place.
      String osName = System.getProperty("os.name").toLowerCase();
      if (programName.equals("ISN") && !osName.contains("windows")) {
        install = new File(linux, "ctpService-red.sh");
        cp.appendln(Color.black, "ISN service installer:");
        cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
        bat = getFileText(install);
        bat = replace(bat, props); // do the substitutions
        bat = bat.replace("\r", "");
        File initDir = new File("/etc/init.d");
        File initFile = new File(initDir, "ctpService");
        if (initDir.exists()) {
          setOwnership(initDir, "edge", "edge");
          setFileText(initFile, bat);
          initFile.setReadable(true, false); // everybody can read //Java 1.6
          initFile.setWritable(true); // only the owner can write //Java 1.6
          initFile.setExecutable(true, false); // everybody can execute //Java 1.6
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println("Unable to update the Linux service ctpService.sh file");
    }
  }
Example #10
0
  public static void main(String[] args) throws Exception {
    Path dir1 = TestUtil.createTemporaryDirectory();
    try {

      // Same directory
      testCopyFileToFile(dir1, dir1, TestUtil.supportsLinks(dir1));
      testMove(dir1, dir1, TestUtil.supportsLinks(dir1));

      // Different directories. Use test.dir if possible as it might be
      // a different volume/file system and so improve test coverage.
      String testDir = System.getProperty("test.dir", ".");
      Path dir2 = TestUtil.createTemporaryDirectory(testDir);
      try {
        boolean testSymbolicLinks = TestUtil.supportsLinks(dir1) && TestUtil.supportsLinks(dir2);
        testCopyFileToFile(dir1, dir2, testSymbolicLinks);
        testMove(dir1, dir2, testSymbolicLinks);
      } finally {
        TestUtil.removeAll(dir2);
      }

      // Target is location associated with custom provider
      Path dir3 = PassThroughFileSystem.create().getPath(dir1.toString());
      testCopyFileToFile(dir1, dir3, false);
      testMove(dir1, dir3, false);

      // Test copy(InputStream,Path) and copy(Path,OutputStream)
      testCopyInputStreamToFile();
      testCopyFileToOuputStream();

    } finally {
      TestUtil.removeAll(dir1);
    }
  }
Example #11
0
 private boolean istWindows() {
   boolean retValue = false;
   if (System.getProperty("os.name").contains("Windows")) {
     retValue = true;
   }
   return retValue;
 }
Example #12
0
  public static void main(String[] args) throws MessagingException, IOException {
    Properties props = new Properties();
    try (InputStream in = Files.newInputStream(Paths.get("mail", "mail.properties"))) {
      props.load(in);
    }
    List<String> lines = Files.readAllLines(Paths.get(args[0]), Charset.forName("UTF-8"));

    String from = lines.get(0);
    String to = lines.get(1);
    String subject = lines.get(2);

    StringBuilder builder = new StringBuilder();
    for (int i = 3; i < lines.size(); i++) {
      builder.append(lines.get(i));
      builder.append("\n");
    }

    Console console = System.console();
    String password = new String(console.readPassword("Password: "));

    Session mailSession = Session.getDefaultInstance(props);
    // mailSession.setDebug(true);
    MimeMessage message = new MimeMessage(mailSession);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);
    message.setText(builder.toString());
    Transport tr = mailSession.getTransport();
    try {
      tr.connect(null, password);
      tr.sendMessage(message, message.getAllRecipients());
    } finally {
      tr.close();
    }
  }
 final void checkWriteExtended() {
   SecurityManager sm = System.getSecurityManager();
   if (sm != null) {
     file.checkWrite();
     sm.checkPermission(new RuntimePermission("accessUserInformation"));
   }
 }
  static {
    long time = System.currentTimeMillis();
    ISubgraphTemplate graph = GoogleGraphLoader.constructGoogleGraph();
    System.out.println("graph load: " + (System.currentTimeMillis() - time) / 1000.0);

    time = System.currentTimeMillis();
    _partition =
        new BasePartition(
            1,
            graph,
            PropertySet.EmptyPropertySet,
            PropertySet.EmptyPropertySet,
            Long2IntMaps.EMPTY_MAP,
            new TestSubgraphFactory());
    System.out.println("graph partitioning: " + (System.currentTimeMillis() - time) / 1000.0);
  }
Example #15
0
 public static void main(String[] args) {
   String pathToDB = "test";
   String source = ".";
   if (args.length == 2 || args.length == 4) {
     for (int i = 0; i < args.length; i++) {
       if ("-db".equals(args[i])) {
         pathToDB = args[i + 1];
         i++;
       }
       if ("-source".equals(args[i])) {
         source = args[i + 1];
         i++;
       }
     }
   } else {
     System.err.println(
         "Usage: java "
             + MediaIndexer.class.getName()
             + "[-db path_to_db] -source folder_or_file_to_process");
     System.exit(0);
   }
   ThumbStore ts = new ThumbStore(pathToDB);
   MediaIndexer tb = new MediaIndexer(ts);
   File fs = new File(source);
   tb.processMTRoot(source);
 }
Example #16
0
  public void run() throws Exception {
    File rtDir = new File("rt.dir");
    File javaHome = new File(System.getProperty("java.home"));
    if (javaHome.getName().equals("jre")) javaHome = javaHome.getParentFile();
    File rtJar = new File(new File(new File(javaHome, "jre"), "lib"), "rt.jar");
    expand(rtJar, rtDir);

    String[] rtDir_opts = {
      "-bootclasspath", rtDir.toString(),
      "-classpath", "",
      "-sourcepath", "",
      "-extdirs", ""
    };
    test(rtDir_opts, "HelloPathWorld");

    if (isJarFileSystemAvailable()) {
      String[] rtJar_opts = {
        "-bootclasspath", rtJar.toString(),
        "-classpath", "",
        "-sourcepath", "",
        "-extdirs", ""
      };
      test(rtJar_opts, "HelloPathWorld");

      String[] default_opts = {};
      test(default_opts, "HelloPathWorld");

      // finally, a non-trivial program
      test(default_opts, "CompileTest");
    } else System.err.println("jar file system not available: test skipped");
  }
 /** Permission checks to access file */
 private void checkAccess(UnixPath file, boolean checkRead, boolean checkWrite) {
   SecurityManager sm = System.getSecurityManager();
   if (sm != null) {
     if (checkRead) file.checkRead();
     if (checkWrite) file.checkWrite();
     sm.checkPermission(new RuntimePermission("accessUserInformation"));
   }
 }
Example #18
0
  // copy source to target with verification
  static void copyAndVerify(Path source, Path target, CopyOption... options) throws IOException {
    Path result = copy(source, target, options);
    assertTrue(result == target);

    // get attributes of source and target file to verify copy
    boolean followLinks = true;
    LinkOption[] linkOptions = new LinkOption[0];
    boolean copyAttributes = false;
    for (CopyOption opt : options) {
      if (opt == NOFOLLOW_LINKS) {
        followLinks = false;
        linkOptions = new LinkOption[] {NOFOLLOW_LINKS};
      }
      if (opt == COPY_ATTRIBUTES) copyAttributes = true;
    }
    BasicFileAttributes basicAttributes =
        readAttributes(source, BasicFileAttributes.class, linkOptions);

    // check hash if regular file
    if (basicAttributes.isRegularFile()) assertTrue(computeHash(source) == computeHash(target));

    // check link target if symbolic link
    if (basicAttributes.isSymbolicLink())
      assert (readSymbolicLink(source).equals(readSymbolicLink(target)));

    // check that attributes are copied
    if (copyAttributes && followLinks) {
      checkBasicAttributes(
          basicAttributes, readAttributes(source, BasicFileAttributes.class, linkOptions));

      // verify other attributes when same provider
      if (source.getFileSystem().provider() == target.getFileSystem().provider()) {

        // check POSIX attributes are copied
        String os = System.getProperty("os.name");
        if ((os.equals("SunOS") || os.equals("Linux")) && testPosixAttributes) {
          checkPosixAttributes(
              readAttributes(source, PosixFileAttributes.class, linkOptions),
              readAttributes(target, PosixFileAttributes.class, linkOptions));
        }

        // check DOS attributes are copied
        if (os.startsWith("Windows")) {
          checkDosAttributes(
              readAttributes(source, DosFileAttributes.class, linkOptions),
              readAttributes(target, DosFileAttributes.class, linkOptions));
        }

        // check named attributes are copied
        if (followLinks
            && getFileStore(source).supportsFileAttributeView("xattr")
            && getFileStore(target).supportsFileAttributeView("xattr")) {
          checkUserDefinedFileAttributes(
              readUserDefinedFileAttributes(source), readUserDefinedFileAttributes(target));
        }
      }
    }
  }
Example #19
0
 /** Puts library to temp dir and loads to memory */
 private static void loadLib(String name) {
   Path sourcePath = Paths.get(LIBPATH, name);
   try {
     Path libPath = Files.copy(sourcePath, tempPath, StandardCopyOption.REPLACE_EXISTING);
     System.load(libPath.toString());
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Example #20
0
  /**
   * 以阻塞的方式立即下载一个文件,该方法会覆盖已经存在的文件
   *
   * @param task
   * @return "ok" if download success (else return errmessage);
   */
  static String download(DownloadTask task) {
    if (!openedStatus && show) openStatus();

    URL url;
    HttpURLConnection conn;
    try {
      url = new URL(task.getOrigin());
      conn = (HttpURLConnection) url.openConnection();
      conn.setConnectTimeout(30000);
      conn.setReadTimeout(30000);
      conn.setRequestProperty(
          "User-Agent",
          "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/"
              + Math.random());
      if ("www.imgjav.com".equals(url.getHost())) { // 该网站需要带cookie请求
        conn.setRequestProperty(
            "User-Agent",
            "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36");
        // conn.setRequestProperty("Cookie", "__cfduid=d219ea333c7a9b5743b572697b631925a1446093229;
        // cf_clearance=6ae62d843f5d09acf393f9e4eb130d9366840c82-1446093303-28800");
        conn.setRequestProperty(
            "Cookie",
            "__cfduid=d6ee846b378bb7d5d173a05541f8a2b6a1446090548; cf_clearance=ea10e8db31f8b6ee51570b118dd89b7e616d7b62-1446099714-28800");
        conn.setRequestProperty("Host", "www.imgjav.com");
      }
      Path directory = Paths.get(task.getDest()).getParent();
      if (!Files.exists(directory)) Files.createDirectories(directory);
    } catch (Exception e) {
      e.printStackTrace();
      return e.getMessage();
    }

    try (InputStream is = conn.getInputStream();
        BufferedInputStream in = new BufferedInputStream(is);
        FileOutputStream fos = new FileOutputStream(task.getDest());
        OutputStream out = new BufferedOutputStream(fos); ) {
      int length = conn.getContentLength();
      if (length < 1) throw new IOException("length<1");
      byte[] binary = new byte[length];
      byte[] buff = new byte[65536];
      int len;
      int index = 0;
      while ((len = in.read(buff)) != -1) {
        System.arraycopy(buff, 0, binary, index, len);
        index += len;
        allLen += len; // allLen有线程安全的问题 ,可能会不正确。无需精确数据,所以不同步了
        task.setReceivePercent(String.format("%.2f", ((float) index / length) * 100) + "%");
      }
      out.write(binary);
    } catch (IOException e) {
      e.printStackTrace();
      return e.getMessage();
    }
    return "ok";
  }
Example #21
0
 private static void extractAndLoadNativeLibs() throws IOException {
   Path target = Paths.get(ioTmpDir, "/tklib");
   if (!target.toFile().exists()) {
     Files.createDirectories(target);
   }
   final boolean windows = System.getProperty("os.name").equalsIgnoreCase("windows");
   String fileExtension = windows ? "dll" : "so";
   String prefix = windows ? "" : "lib";
   String libPattern = fileExtension.equals("dll") ? "-windows" : "-linux" + "-x86";
   if (System.getProperty("sun.arch.data.model").equals("64")) {
     libPattern += "_64";
   }
   libPattern += "." + fileExtension;
   //		System.err.println(libPattern);
   System.setProperty("java.library.path", target.toString());
   //		System.err.println(System.getProperty("java.library.path"));
   extractAndLoadNativeLib(prefix + "JCudaDriver" + libPattern, target);
   extractAndLoadNativeLib(prefix + "JCudaRuntime" + libPattern, target);
   extractAndLoadNativeLib(prefix + "JCurand" + libPattern, target);
 }
Example #22
0
 public void fileCreatedUpdated(boolean created, boolean modified) {
   if (created) {
     newFiles++;
   }
   if (modified) {
     updatedFiles++;
   }
   recentModifications++;
   processedFiles++;
   //  System.out.println("MediaIndexer.fileCreatedUpdated");
   if (recentModifications > modificationsBeforeReport) {
     System.out.println("\nProcessed files : " + processedFiles + "/" + totalNumberOfFiles);
     System.out.println(
         "Speed : "
             + (currentProgressSize / (System.currentTimeMillis() - lastProgressTime))
             + " MiB/s");
     lastProgressTime = System.currentTimeMillis();
     recentModifications = 0;
     currentProgressSize = 0;
   }
 }
  /** Prints the structure for a given directory or file */
  public static void main(String[] args) throws IOException {
    if (args.length != 1) {
      printUsage();
      System.exit(-1);
    }

    String pathName = args[0];
    Path startingDir = Paths.get(pathName);

    PrintDirectoryStructureWithVisitor pdsv = new PrintDirectoryStructureWithVisitor();
    Files.walkFileTree(startingDir, pdsv);
  }
Example #24
0
  public void processMTRoot(String path) {
    long t0 = System.currentTimeMillis();
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    try {
      ts.addIndexPath(new File(path).getCanonicalPath());
      System.out.println("MediaIndexer.processMTRoot()" + path);
      System.out.println("MediaIndexer.processMTRoot() started at time " + dateFormat.format(date));
      System.out.println("MediaIndexer.processMTRoot() computing number of files...");
      totalNumberOfFiles = this.countFiles(path);
      lastProgressTime = System.currentTimeMillis();
      System.out.println("Number of files to explore " + totalNumberOfFiles);
      if (executorService.isShutdown()) {
        executorService =
            new ThreadPoolExecutor(
                maxThreads, maxThreads, 0L, TimeUnit.MILLISECONDS, new LimitedQueue<Runnable>(50));
      }

      this.processedFiles = 0;
      // this.processMT(new File(path));
      TreeWalker t = new TreeWalker(this);
      t.walk(path);
    } catch (IOException e) {
      e.printStackTrace();
    }
    executorService.shutdown();
    try {
      executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    long t1 = System.currentTimeMillis();
    date = new Date();
    System.out.println("MediaIndexer.processMTRoot() finished at time " + dateFormat.format(date));
    System.out.println("MediaIndexer.processMTRoot() found " + newFiles + " new files");
    System.out.println("MediaIndexer.processMTRoot() updated " + updatedFiles + " files");
    System.out.println("MediaIndexer.processMTRoot() total " + ts.size() + " files");
    System.out.println("MediaIndexer.processMTRoot took " + (t1 - t0) / 1000 + " s");
  }
Example #25
0
  // "randomize" the file attributes of the given file.
  static void randomizeAttributes(Path file) throws IOException {
    String os = System.getProperty("os.name");
    boolean isWindows = os.startsWith("Windows");
    boolean isUnix = os.equals("SunOS") || os.equals("Linux");
    boolean isDirectory = isDirectory(file, NOFOLLOW_LINKS);

    if (isUnix) {
      Set<PosixFilePermission> perms = getPosixFilePermissions(file, NOFOLLOW_LINKS);
      PosixFilePermission[] toChange = {
        PosixFilePermission.GROUP_READ,
        PosixFilePermission.GROUP_WRITE,
        PosixFilePermission.GROUP_EXECUTE,
        PosixFilePermission.OTHERS_READ,
        PosixFilePermission.OTHERS_WRITE,
        PosixFilePermission.OTHERS_EXECUTE
      };
      for (PosixFilePermission perm : toChange) {
        if (heads()) {
          perms.add(perm);
        } else {
          perms.remove(perm);
        }
      }
      setPosixFilePermissions(file, perms);
    }

    if (isWindows) {
      DosFileAttributeView view =
          getFileAttributeView(file, DosFileAttributeView.class, NOFOLLOW_LINKS);
      // only set or unset the hidden attribute
      view.setHidden(heads());
    }

    boolean addUserDefinedFileAttributes =
        heads() && getFileStore(file).supportsFileAttributeView("xattr");

    // remove this when copying a direcory copies its named streams
    if (isWindows && isDirectory) addUserDefinedFileAttributes = false;

    if (addUserDefinedFileAttributes) {
      UserDefinedFileAttributeView view =
          getFileAttributeView(file, UserDefinedFileAttributeView.class);
      int n = rand.nextInt(16);
      while (n > 0) {
        byte[] value = new byte[1 + rand.nextInt(100)];
        view.write("user." + Integer.toString(n), ByteBuffer.wrap(value));
        n--;
      }
    }
  }
Example #26
0
  public double loadBinaryFile() throws IOException {
    double time = System.nanoTime();
    File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\jsfweek14.bin");
    FileChannel fileChannel = null;
    MappedByteBuffer map = null;
    int counter = 0;
    // Now read every edge from the file and draw it.
    try {
      //            fileIn = new FileInputStream(file);
      //            inPut = new DataInputStream(fileIn);
      fileChannel = new RandomAccessFile(file, "r").getChannel();
      map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 4096 * 128 * 128);
      double d = map.getDouble();
      currentLevel = (int) d;
      counter = (int) (3 * Math.pow(4, currentLevel - 1));
      for (int i = 0; i <= counter; i++) {
        double X1 = map.getDouble();
        double Y1 = map.getDouble();
        double X2 = map.getDouble();
        double Y2 = map.getDouble();
        double red = map.getDouble();
        double green = map.getDouble();
        double blue = map.getDouble();

        Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1));
        drawEdge(e);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      fileChannel.close();
      map.clear();
    }

    return System.nanoTime() - time;
  }
Example #27
0
  /**
   * Gets a connection from the properties specified in the file database.properties
   *
   * @return the database connection
   */
  public static Connection getConnection() throws SQLException, IOException {
    Properties props = new Properties();
    try (InputStream in = Files.newInputStream(Paths.get("database.properties"))) {
      props.load(in);
    }

    String drivers = props.getProperty("jdbc.drivers");
    if (drivers != null) System.setProperty("jdbc.drivers", drivers);

    String url = props.getProperty("jdbc.url");
    String username = props.getProperty("jdbc.username");
    String password = props.getProperty("jdbc.password");

    return DriverManager.getConnection(url, username, password);
  }
Example #28
0
  private void parsestories() {

    try {

      List<String> lns =
          Files.readAllLines(Paths.get("datasets/" + name + ".tsv"), Charset.defaultCharset());

      for (String ln : lns) stories.add(Story.fromtext(ln));

    } catch (IOException e) {

      System.out.println("Error reading dataset.");
      System.exit(1);
    }
  }
  public void doSerializationRoundtrip(String serializationType, SliceManager sliceManager)
      throws IOException {
    long time = System.currentTimeMillis();
    long bytes = sliceManager.writePartition(_partition);
    System.out.println(
        serializationType
            + " serialization: "
            + (System.currentTimeMillis() - time) / 1000.0
            + "s , "
            + bytes / 1000.0
            + "kb");

    time = System.currentTimeMillis();
    IPartition actualPartition = sliceManager.readPartition();
    System.out.println(
        serializationType
            + " deserialization: "
            + (System.currentTimeMillis() - time) / 1000.0
            + "s");

    assertEquals(_partition, actualPartition);

    sliceManager.deletePartition();
  }
Example #30
0
 private void fixRSNAROOT(Element server) {
   if (programName.equals("ISN")) {
     Element ssl = getFirstNamedChild(server, "SSL");
     if (ssl != null) {
       if (System.getProperty("os.name").contains("Windows")) {
         ssl.setAttribute(
             "keystore", ssl.getAttribute("keystore").replace("RSNA_HOME", "RSNA_ROOT"));
         ssl.setAttribute(
             "truststore", ssl.getAttribute("truststore").replace("RSNA_HOME", "RSNA_ROOT"));
       } else {
         ssl.setAttribute("keystore", "${RSNA_ROOT}/conf/keystore.jks");
         ssl.setAttribute("truststore", "${RSNA_ROOT}/conf/truststore.jks");
       }
     }
   }
 }