Example #1
0
 /**
  * 复制文件或目录
  *
  * @param src the src
  * @param tar the tar
  * @return the boolean
  */
 public static boolean copy(File src, File tar) {
   try {
     LogUtils.debug(String.format("copy %s to %s", src.getAbsolutePath(), tar.getAbsolutePath()));
     if (src.isFile()) {
       InputStream is = new FileInputStream(src);
       OutputStream op = new FileOutputStream(tar);
       BufferedInputStream bis = new BufferedInputStream(is);
       BufferedOutputStream bos = new BufferedOutputStream(op);
       byte[] bt = new byte[1024 * 8];
       int len = bis.read(bt);
       while (len != -1) {
         bos.write(bt, 0, len);
         len = bis.read(bt);
       }
       bis.close();
       bos.close();
     } else if (src.isDirectory()) {
       File[] files = src.listFiles();
       //noinspection ResultOfMethodCallIgnored
       tar.mkdirs();
       for (File file : files) {
         copy(
             file.getAbsoluteFile(),
             new File(tar.getAbsoluteFile() + File.separator + file.getName()));
       }
     }
     return true;
   } catch (Exception e) {
     LogUtils.error(e);
     return false;
   }
 }
Example #2
0
  private short calculateSymlink(File file, short st_mode) throws IOException {
    if (file.getAbsoluteFile().getParentFile() == null) {
      return st_mode;
    }

    File absoluteParent = file.getAbsoluteFile().getParentFile();
    File canonicalParent = absoluteParent.getCanonicalFile();

    if (canonicalParent.getAbsolutePath().equals(absoluteParent.getAbsolutePath())) {
      // parent doesn't change when canonicalized, compare absolute and canonical file directly
      if (!file.getAbsolutePath().equalsIgnoreCase(file.getCanonicalPath())) {
        st_mode |= S_IFLNK;
        return st_mode;
      }
    }

    // directory itself has symlinks (canonical != absolute), so build new path with canonical
    // parent and compare
    file = new JavaSecuredFile(canonicalParent.getAbsolutePath() + "/" + file.getName());
    if (!file.getAbsolutePath().equalsIgnoreCase(file.getCanonicalPath())) {
      st_mode |= S_IFLNK;
    }

    return st_mode;
  }
  private void copyAllFilesToLogDir(File node, File parent) throws IOException {
    if (!node.getAbsoluteFile().equals(parent.getAbsoluteFile())
        && node.isFile()
        && !node.getParentFile().equals(parent)) {
      String fileNamePrefix = node.getName().substring(0, node.getName().lastIndexOf('.'));
      String fileNameSuffix = node.getName().substring(node.getName().lastIndexOf('.'));
      String newFilePath =
          node.getParentFile().getAbsolutePath()
              + File.separator
              + fileNamePrefix.replace(".", "_")
              + fileNameSuffix;

      File newNode = new File(newFilePath);
      if (node.renameTo(newNode)) {
        FileUtils.copyFileToDirectory(newNode, parent);
      }
    }
    if (node.isDirectory()) {
      String[] subNote = node.list();
      for (String filename : subNote) {
        copyAllFilesToLogDir(new File(node, filename), parent);
      }
      if (!node.equals(parent)) {
        FileUtils.deleteDirectory(node);
      }
    }
  }
Example #4
0
 /**
  * Test of doOCR method, of class Tesseract.
  *
  * @throws Exception while processing image.
  */
 @Test
 public void testDoOCR_List_Rectangle() throws Exception {
   File imageFile = null;
   String expResult = "The (quick) [brown] {fox} jumps!\nOver the $43,456.78 <lazy> #90 dog";
   String result = "<empty>";
   try {
     logger.info("doOCR on a PDF document");
     imageFile = new File(this.testResourcesDataPath, "eurotext.pdf");
     List<IIOImage> imageList = ImageIOHelper.getIIOImageList(imageFile);
     result = instance.doOCR(imageList, null);
     logger.info(result);
     assertEquals(expResult, result.substring(0, expResult.length()));
   } catch (IOException e) {
     logger.error(
         "Exception-Message: '{}'. Imagefile: '{}'",
         e.getMessage(),
         imageFile.getAbsoluteFile(),
         e);
     fail();
   } catch (TesseractException e) {
     logger.error(
         "Exception-Message: '{}'. Imagefile: '{}'",
         e.getMessage(),
         imageFile.getAbsoluteFile(),
         e);
     fail();
   } catch (StringIndexOutOfBoundsException e) {
     logger.error(
         "Exception-Message: '{}'. Imagefile: '{}'",
         e.getMessage(),
         imageFile.getAbsoluteFile(),
         e);
     fail();
   }
 }
Example #5
0
  @Override
  public void transformCode(final StringBuilder messages, StringWriter result, final File file)
      throws Throwable {
    delombok.setVerbose(false);
    delombok.setForceProcess(true);
    delombok.setCharset("UTF-8");

    delombok.setDiagnosticsListener(
        new DiagnosticListener<JavaFileObject>() {
          @Override
          public void report(Diagnostic<? extends JavaFileObject> d) {
            String msg = d.getMessage(Locale.ENGLISH);
            Matcher m =
                Pattern.compile(
                        "^"
                            + Pattern.quote(file.getAbsolutePath())
                            + "\\s*:\\s*\\d+\\s*:\\s*(?:warning:\\s*)?(.*)$",
                        Pattern.DOTALL)
                    .matcher(msg);
            if (m.matches()) msg = m.group(1);
            messages.append(
                String.format(
                    "%d:%d %s %s\n", d.getLineNumber(), d.getColumnNumber(), d.getKind(), msg));
          }
        });

    delombok.addFile(file.getAbsoluteFile().getParentFile(), file.getName());
    delombok.setSourcepath(file.getAbsoluteFile().getParent());
    delombok.setWriter(result);
    delombok.delombok();
  }
Example #6
0
  @Before
  public void setUp() throws IOException { // complete input.txt
    try {

      String content = "{()}";
      String contentFormatted = "{\n ( ) \n}";

      File file = new File(fileName);

      // if file doesnt exists, then create it and complete
      if (!file.exists()) {
        file.createNewFile();
        java.io.FileWriter fw = new java.io.FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(content);
        bw.close();
      }

      File fileOut = new File(fileNameOutR);
      // if fileOut doesnt exists, then create it and complete
      if (!fileOut.exists()) {
        fileOut.createNewFile();
        java.io.FileWriter fwOut = new java.io.FileWriter(fileOut.getAbsoluteFile());
        BufferedWriter bwOut = new BufferedWriter(fwOut);
        bwOut.write(contentFormatted);
        bwOut.close();
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #7
0
  /**
   * Creates a JSONObject that represents a File from the Uri
   *
   * @param data the Uri of the audio/image/video
   * @return a JSONObject that represents a File
   * @throws IOException
   */
  private JSONObject createMediaFile(Uri data) {
    File fp = new File(getRealPathFromURI(data, getActivity()));
    JSONObject obj = new JSONObject();

    try {
      // File properties
      obj.put(MEDIA_FILE_NAME_FIELD, fp.getName());
      obj.put(FILE_PATH_FIELD, "file://" + fp.getAbsolutePath());
      // Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
      // are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
      // is stored in the audio or video content store.
      if (fp.getAbsoluteFile().toString().endsWith(".3gp")
          || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
        if (data.toString().contains("/audio/")) {
          obj.put(FILE_TYPE_FIELD, AUDIO_3GPP);
        } else {
          obj.put(FILE_TYPE_FIELD, VIDEO_3GPP);
        }
      } else {
        obj.put(FILE_TYPE_FIELD, getMimeType(fp.getAbsolutePath()));
      }

      obj.put(FILE_MODIFIED_FIELD, fp.lastModified());
      obj.put(FILE_SIZE_FIELD, fp.length());
    } catch (JSONException e) {
      e.printStackTrace();
      return null;
    }

    return obj;
  }
 protected void checkStartParameter(StartParameter startParameter) {
   assertEquals(expectedBuildFile, startParameter.getBuildFile());
   assertEquals(expectedTaskNames, startParameter.getTaskNames());
   assertEquals(buildProjectDependencies, startParameter.isBuildProjectDependencies());
   if (expectedCurrentDir != null) {
     assertEquals(
         expectedCurrentDir.getAbsoluteFile(), startParameter.getCurrentDir().getAbsoluteFile());
   }
   assertEquals(expectedProjectDir, startParameter.getProjectDir());
   assertEquals(expectedSearchUpwards, startParameter.isSearchUpwards());
   assertEquals(expectedProjectProperties, startParameter.getProjectProperties());
   assertEquals(expectedSystemProperties, startParameter.getSystemPropertiesArgs());
   assertEquals(
       expectedGradleUserHome.getAbsoluteFile(),
       startParameter.getGradleUserHomeDir().getAbsoluteFile());
   assertEquals(expectedLogLevel, startParameter.getLogLevel());
   assertEquals(expectedColorOutput, startParameter.isColorOutput());
   assertEquals(expectedConsoleOutput, startParameter.getConsoleOutput());
   assertEquals(expectedDryRun, startParameter.isDryRun());
   assertEquals(expectedShowStackTrace, startParameter.getShowStacktrace());
   assertEquals(expectedExcludedTasks, startParameter.getExcludedTaskNames());
   assertEquals(expectedInitScripts, startParameter.getInitScripts());
   assertEquals(expectedProfile, startParameter.isProfile());
   assertEquals(expectedContinue, startParameter.isContinueOnFailure());
   assertEquals(expectedOffline, startParameter.isOffline());
   assertEquals(expectedRecompileScripts, startParameter.isRecompileScripts());
   assertEquals(expectedRerunTasks, startParameter.isRerunTasks());
   assertEquals(expectedRefreshDependencies, startParameter.isRefreshDependencies());
   assertEquals(expectedProjectCacheDir, startParameter.getProjectCacheDir());
   assertEquals(expectedParallelExecutorCount, startParameter.getParallelThreadCount());
   assertEquals(expectedConfigureOnDemand, startParameter.isConfigureOnDemand());
   assertEquals(expectedMaxWorkersCount, startParameter.getMaxWorkerCount());
   assertEquals(expectedContinuous, startParameter.isContinuous());
 }
Example #9
0
  /**
   * Move the files of the deliver to a new path. If old path
   *
   * @param dstPath Path to store the files. It cannot exist previously.
   * @return True if all files have been correctly moved to the new path of False otherwise
   */
  public boolean moveFiles(File dstPath) {
    // Check that destination folder does not exist
    if (dstPath.getAbsoluteFile().exists()) {
      return false;
    }

    // Create the output path
    if (!dstPath.getAbsoluteFile().mkdirs()) {
      return false;
    }

    // Move the files
    for (DeliverFile f : _files) {
      if (!f.getAbsolutePath(_rootPath).renameTo(f.getAbsolutePath(dstPath))) {
        return false;
      }
    }

    // Remove old path
    _rootPath.getAbsoluteFile().delete();

    // Change the root path to the new folder
    _rootPath = dstPath;

    return true;
  }
 @Before
 public void setup() throws Exception {
   FileContext files = FileContext.getLocalFSFileContext();
   Path workSpacePath = new Path(workSpace.getAbsolutePath());
   files.mkdir(workSpacePath, null, true);
   FileUtil.chmod(workSpace.getAbsolutePath(), "777");
   File localDir = new File(workSpace.getAbsoluteFile(), "localDir");
   files.mkdir(new Path(localDir.getAbsolutePath()), new FsPermission("777"), false);
   File logDir = new File(workSpace.getAbsoluteFile(), "logDir");
   files.mkdir(new Path(logDir.getAbsolutePath()), new FsPermission("777"), false);
   String exec_path = System.getProperty("container-executor.path");
   if (exec_path != null && !exec_path.isEmpty()) {
     Configuration conf = new Configuration(false);
     LOG.info("Setting " + YarnConfiguration.NM_LINUX_CONTAINER_EXECUTOR_PATH + "=" + exec_path);
     conf.set(YarnConfiguration.NM_LINUX_CONTAINER_EXECUTOR_PATH, exec_path);
     exec = new LinuxContainerExecutor();
     exec.setConf(conf);
     conf.set(YarnConfiguration.NM_LOCAL_DIRS, localDir.getAbsolutePath());
     conf.set(YarnConfiguration.NM_LOG_DIRS, logDir.getAbsolutePath());
     dirsHandler = new LocalDirsHandlerService();
     dirsHandler.init(conf);
   }
   appSubmitter = System.getProperty("application.submitter");
   if (appSubmitter == null || appSubmitter.isEmpty()) {
     appSubmitter = "nobody";
   }
 }
  @Override
  protected void setValue(Resource value) {
    if (value == null) {
      _filenameField.setFilename("");
      _otherPathTextField.setText("");
      return;
    }

    if (value instanceof FileResource) {
      _resourceTypeComboBox.setSelectedItem("file");
      File existingFile = _filenameField.getFile();
      File newFile = ((FileResource) value).getFile();
      if (existingFile != null
          && existingFile.getAbsoluteFile().equals(newFile.getAbsoluteFile())) {
        return;
      }
      _filenameField.setFile(newFile);
    } else if (value instanceof UrlResource) {
      _resourceTypeComboBox.setSelectedItem("url");
      final String url = ((UrlResource) value).getUri().toString();
      _otherPathTextField.setText(url);
    } else if (value instanceof ClasspathResource) {
      _resourceTypeComboBox.setSelectedItem("classpath");
      final String resourcePath = ((ClasspathResource) value).getResourcePath();
      _otherPathTextField.setText(resourcePath);
    } else if (value instanceof VfsResource) {
      _resourceTypeComboBox.setSelectedItem("vfs");
      final String path = ((VfsResource) value).getFileObject().getName().getURI();
      _otherPathTextField.setText(path);
    } else {
      throw new UnsupportedOperationException("Unsupported resource type: " + value);
    }
  }
Example #12
0
 /**
  * @param file the {@link File} to make relative
  * @param relativeTo the {@link File} (or directory) that file should be made relative to.
  * @return a {@link String} with the relative file path.
  */
 public static String getFilePathRelativeTo(File file, File relativeTo) {
   return relativeTo
       .getAbsoluteFile()
       .toURI()
       .relativize(file.getAbsoluteFile().toURI())
       .toString();
 }
  /**
   * Creates a JSONObject that represents a File from the Uri
   *
   * @param data the Uri of the audio/image/video
   * @return a JSONObject that represents a File
   * @throws IOException
   */
  private JSONObject createMediaFile(Uri data) {
    File fp = webView.getResourceApi().mapUriToFile(data);
    JSONObject obj = new JSONObject();

    try {
      // File properties
      obj.put("name", fp.getName());
      obj.put("fullPath", fp.toURI().toString());
      // Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
      // are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
      // is stored in the audio or video content store.
      if (fp.getAbsoluteFile().toString().endsWith(".3gp")
          || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
        if (data.toString().contains("/audio/")) {
          obj.put("type", AUDIO_3GPP);
        } else {
          obj.put("type", VIDEO_3GPP);
        }
      } else {
        obj.put("type", FileHelper.getMimeType(Uri.fromFile(fp), cordova));
      }

      obj.put("lastModifiedDate", fp.lastModified());
      obj.put("size", fp.length());
    } catch (JSONException e) {
      // this will never happen
      e.printStackTrace();
    }

    return obj;
  }
  @Test
  @Ignore("disabled because it's a blinking test. If run standalone it works very well.")
  public void testNCSALogger() throws Exception {
    testServletPath();

    final File logFile = new File("target/logs/request.log");

    if (!logFile.exists()) logFile.getParentFile().mkdirs();

    LOG.info("Log-File: {}", logFile.getAbsoluteFile());

    assertNotNull(logFile);

    new WaitCondition("logfile") {
      @Override
      protected boolean isFulfilled() throws Exception {
        return logFile.exists();
      }
    }.waitForCondition();

    boolean exists = logFile.getAbsoluteFile().exists();

    assertTrue(exists);

    FileInputStream fstream = new FileInputStream(logFile.getAbsoluteFile());
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine = br.readLine();
    assertNotNull(strLine);
    in.close();
    fstream.close();
  }
 private boolean dotestReadAndWrite(String directoryName) {
   File directory = new File(directoryName);
   Log.d(TAG, " _______-------- dotestReadAndWrite()0, directoryName = " + directoryName);
   if (!directory.isDirectory()) {
     if (!directory.mkdirs()) {
       Log.d(TAG, " _______-------- dotestReadAndWrite()0 1, directoryName = " + directoryName);
       return false;
     }
   }
   File f = new File(directoryName, "storagetest.txt");
   try {
     if (f.exists()) {
       f.delete();
     }
     if (!f.createNewFile()) {
       return false;
     } else {
       doWriteFile(f.getAbsoluteFile().toString());
       if (!doReadFile(f.getAbsoluteFile().toString()).equals(TEST_STRING)) {
         return false;
       }
     }
     f.delete();
     return true;
   } catch (IOException ex) {
     Log.e(TAG, "isWritable : false (IOException)!");
     return false;
   }
 }
Example #16
0
  /**
   * Does the actual parsing of a devices.xml file.
   *
   * @param deviceXml the {@link File} to load/parse. This must be an existing file.
   * @param list the list in which to write the parsed {@link LayoutDevice}.
   */
  private void parseLayoutDevices(File deviceXml, List<LayoutDevice> list) {
    // first we validate the XML
    try {
      Source source = new StreamSource(new FileReader(deviceXml));

      CaptureErrorHandler errorHandler = new CaptureErrorHandler(deviceXml.getAbsolutePath());

      Validator validator = LayoutDevicesXsd.getValidator(errorHandler);
      validator.validate(source);

      if (errorHandler.foundError() == false) {
        // do the actual parsing
        LayoutDeviceHandler handler = new LayoutDeviceHandler();

        SAXParser parser = mParserFactory.newSAXParser();
        parser.parse(new InputSource(new FileInputStream(deviceXml)), handler);

        // get the parsed devices
        list.addAll(handler.getDevices());
      }
    } catch (SAXException e) {
      AdtPlugin.log(e, "Error parsing %1$s", deviceXml.getAbsoluteFile());
    } catch (FileNotFoundException e) {
      // this shouldn't happen as we check above.
    } catch (IOException e) {
      AdtPlugin.log(e, "Error reading %1$s", deviceXml.getAbsoluteFile());
    } catch (ParserConfigurationException e) {
      AdtPlugin.log(e, "Error parsing %1$s", deviceXml.getAbsoluteFile());
    }
  }
Example #17
0
  public void saveLogData() {

    Long tsLong = System.currentTimeMillis() / 1000;
    String ts = tsLong.toString();

    File mydir = new File(Environment.getExternalStorageDirectory() + "/Ajna/", "Logs");
    if (!mydir.exists()) mydir.mkdirs();

    File log28File = new File(mydir, ts + "LOG-28.csv");
    File log26File = new File(mydir, ts + "LOG-26.csv");
    // File log27File = new File(mydir, ts + "LOG-27.csv");

    try {
      FileWriter fw = new FileWriter(log28File.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      /*
                  StringBuilder readableLog28 = new StringBuilder();
                  StringBuilder output = removeBlankSpace(log28);


                  for (int i = 0; i < log28.length(); i += 2) {
                      String str = log28.substring(i, i + 2);
                      readableLog28.append((char) Integer.parseInt(str, 16));
                  }
      */

      // bw.write(readableLog28.toString());
      bw.write(log28.toString());
      bw.close();

      Toast.makeText(this, "Log 28 Captured", Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      FileWriter fw = new FileWriter(log26File.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);
      bw.write(log26.toString());
      bw.close();

      Toast.makeText(this, "Log 26 Captured", Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
      e.printStackTrace();
    }

    write27LogData(mydir, ts, "LOG-27");

    log26.setLength(0);
    log27_a.setLength(0);
    log27_g.setLength(0);
    log27_q.setLength(0);
    log27_e.setLength(0);
    log27_h.setLength(0);

    log27.setLength(0);
    log28.setLength(0);
  }
Example #18
0
  /**
   * Compare two text files. Ignores different line separators. As there are: LF, CR, CR + LF, NEL,
   * FF, LS, PS.
   *
   * @param from Compare source.
   * @param with Compare with this file.
   * @param encoding Use this character encoding. Must not be <code>null</code>.
   * @return Is the contents of the two text files equal?
   * @throws IOException File exception occurred or encoding is not supported.
   * @throws NullPointerException Is encoding different from <code>null</code>?
   */
  public static boolean compareTextFiles(final File from, final File with, final String encoding)
      throws IOException {
    if (from == null && with == null) {
      return true;
    }
    if (from == null || with == null) {
      return false;
    }
    if (from.getAbsoluteFile().equals(with.getAbsoluteFile())) {
      return true;
    }

    BufferedReader one = null;
    BufferedReader two = null;
    FileInputStream fromIn = null;
    FileInputStream withIn = null;
    try {
      fromIn = new FileInputStream(from);
      one = new BufferedReader(new InputStreamReader(fromIn, encoding));
      withIn = new FileInputStream(with);
      two = new BufferedReader(new InputStreamReader(withIn, encoding));

      boolean crOne = false;
      boolean crTwo = false;
      do {
        int readOne = one.read();
        int readTwo = two.read();
        if (readOne == readTwo) {
          if (readOne < 0) {
            break;
          }
        } else {
          crOne = readOne == 0x0D;
          crTwo = readTwo == 0x0D;
          if (crOne) {
            readOne = one.read();
          }
          if (crTwo) {
            readTwo = two.read();
          }
          if (crOne && readOne != 0x0A && isCr(readTwo)) {
            readTwo = two.read();
          }
          if (crTwo && readTwo != 0x0A && isCr(readOne)) {
            readOne = one.read();
          }
          if (readOne != readTwo && (!isCr(readOne) && !isCr(readTwo))) {
            return false;
          }
        }
      } while (true);
      return true;
    } finally {
      close(fromIn);
      close(one);
      close(two);
      close(withIn);
    }
  }
  /**
   * Write a DOM-Tree to a target file.
   *
   * @param target File to write to.
   * @param dom dom to write to file.
   * @throws IOException in case of unexpected writer exceptions.
   */
  private void writeDomToTarget(final File target, final Xpp3Dom dom) throws IOException {
    if (getLog().isDebugEnabled())
      getLog().debug("writing: " + dom.getName() + " to: " + target.getAbsoluteFile());

    final XmlStreamWriter writer = WriterFactory.newXmlWriter(target);
    final PrettyPrintXMLWriter pretty = new PrettyPrintXMLWriter(writer);
    Xpp3DomWriter.write(pretty, dom);
    writer.close();
    if (getLog().isDebugEnabled())
      getLog().debug(dom.getName() + " written to: " + target.getAbsoluteFile());
  }
  private Set<FileInfo> resolveFiles(List<String> files, boolean serveOnly) {
    if (files != null) {
      Set<FileInfo> resolvedFiles = new LinkedHashSet<FileInfo>();

      for (String f : files) {
        f = pathRewriter.rewrite(f);
        boolean isPatch = f.startsWith("patch");

        if (isPatch) {
          String[] tokens = f.split(" ", 2);

          f = tokens[1].trim();
        }
        if (f.startsWith("http://") || f.startsWith("https://")) {
          resolvedFiles.add(new FileInfo(f, -1, -1, false, false, null));
        } else {
          File file = basePath != null ? new File(basePath.getAbsoluteFile(), f) : new File(f);
          File testFile = file.getAbsoluteFile();
          File dir = testFile.getParentFile().getAbsoluteFile();
          final String pattern = file.getName();
          String[] filteredFiles =
              dir.list(
                  new GlobFilenameFilter(
                      pattern, GlobCompiler.DEFAULT_MASK | GlobCompiler.CASE_INSENSITIVE_MASK));

          if (filteredFiles == null || filteredFiles.length == 0) {
            String error =
                "The patterns/paths "
                    + f
                    + " used in the configuration"
                    + " file didn't match any file, the files patterns/paths need to be relative to"
                    + " the configuration file.";

            System.err.println(error);
            throw new RuntimeException(error);
          }
          Arrays.sort(filteredFiles, String.CASE_INSENSITIVE_ORDER);

          for (String filteredFile : filteredFiles) {
            String resolvedFilePath =
                pathResolver.resolvePath(
                    dir.getAbsolutePath() + FileInfo.SEPARATOR_CHAR + filteredFile);
            File resolvedFile = new File(resolvedFilePath);

            resolvedFiles.add(
                new FileInfo(
                    resolvedFilePath, resolvedFile.lastModified(), -1, isPatch, serveOnly, null));
          }
        }
      }
      return resolvedFiles;
    }
    return Collections.emptySet();
  }
  /** Test that DataStorage and BlockPoolSliceStorage remove the failed volume after failure. */
  @Test(timeout = 150000)
  public void testFailedVolumeBeingRemovedFromDataNode()
      throws InterruptedException, IOException, TimeoutException {
    // The test uses DataNodeTestUtils#injectDataDirFailure() to simulate
    // volume failures which is currently not supported on Windows.
    assumeTrue(!Path.WINDOWS);

    Path file1 = new Path("/test1");
    DFSTestUtil.createFile(fs, file1, 1024, (short) 2, 1L);
    DFSTestUtil.waitReplication(fs, file1, (short) 2);

    File dn0Vol1 = new File(dataDir, "data" + (2 * 0 + 1));
    DataNodeTestUtils.injectDataDirFailure(dn0Vol1);
    DataNode dn0 = cluster.getDataNodes().get(0);
    checkDiskErrorSync(dn0);

    // Verify dn0Vol1 has been completely removed from DN0.
    // 1. dn0Vol1 is removed from DataStorage.
    DataStorage storage = dn0.getStorage();
    assertEquals(1, storage.getNumStorageDirs());
    for (int i = 0; i < storage.getNumStorageDirs(); i++) {
      Storage.StorageDirectory sd = storage.getStorageDir(i);
      assertFalse(sd.getRoot().getAbsolutePath().startsWith(dn0Vol1.getAbsolutePath()));
    }
    final String bpid = cluster.getNamesystem().getBlockPoolId();
    BlockPoolSliceStorage bpsStorage = storage.getBPStorage(bpid);
    assertEquals(1, bpsStorage.getNumStorageDirs());
    for (int i = 0; i < bpsStorage.getNumStorageDirs(); i++) {
      Storage.StorageDirectory sd = bpsStorage.getStorageDir(i);
      assertFalse(sd.getRoot().getAbsolutePath().startsWith(dn0Vol1.getAbsolutePath()));
    }

    // 2. dn0Vol1 is removed from FsDataset
    FsDatasetSpi<? extends FsVolumeSpi> data = dn0.getFSDataset();
    try (FsDatasetSpi.FsVolumeReferences vols = data.getFsVolumeReferences()) {
      for (FsVolumeSpi volume : vols) {
        assertNotEquals(
            new File(volume.getBasePath()).getAbsoluteFile(), dn0Vol1.getAbsoluteFile());
      }
    }

    // 3. all blocks on dn0Vol1 have been removed.
    for (ReplicaInfo replica : FsDatasetTestUtil.getReplicas(data, bpid)) {
      assertNotNull(replica.getVolume());
      assertNotEquals(
          new File(replica.getVolume().getBasePath()).getAbsoluteFile(), dn0Vol1.getAbsoluteFile());
    }

    // 4. dn0Vol1 is not in DN0's configuration and dataDirs anymore.
    String[] dataDirStrs = dn0.getConf().get(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY).split(",");
    assertEquals(1, dataDirStrs.length);
    assertFalse(dataDirStrs[0].contains(dn0Vol1.getAbsolutePath()));
  }
Example #22
0
 public void listAllFiles(String path) {
   File root = new File(path);
   File[] list = root.listFiles(new ImageFileFilter());
   if (list != null) { // In case of access error, list is null
     for (File f : list) {
       if (f.isDirectory()) {
         System.out.println(f.getAbsoluteFile());
         listAllFiles(f.getAbsolutePath());
       } else {
         System.out.println(f.getAbsoluteFile());
       }
     }
   }
 }
Example #23
0
  @Override
  protected void startAligner(Mapper.Context context) throws IOException, InterruptedException {
    if (redistribute) {
      getIdleCores(context);
      Logger.DEBUG("Redistributing cores: using " + threads);
    }
    int threadsToUse = threads;
    if (isPaired && threadsToUse > 1) threadsToUse /= 2;
    String[] command1 =
        CommandGenerator.bwaAln(
            bin,
            ref,
            "/dev/stdin",
            getFileName(tmpdir, taskId, true, 1),
            threadsToUse,
            alnCustomArgs);
    reads1 = new ProcessBuilderWrapper(command1, bin);
    reads1.setThreads(threadsToUse);
    reads1.startProcess(null, System.err);
    // check if alive.
    if (!reads1.isAlive()) throw new ProcessException("BWA aln", reads1.getExitState());

    File file1 = new File(getFileName(tmpdir, taskId, false, 1));
    if (!file1.exists()) {
      file1.createNewFile();
    }
    fastqFile1 = new BufferedWriter(new FileWriter(file1.getAbsoluteFile()));
    if (isPaired) {
      if (threads > 1) {
        String[] command2 =
            CommandGenerator.bwaAln(
                bin,
                ref,
                "/dev/stdin",
                getFileName(tmpdir, taskId, true, 2),
                threadsToUse,
                alnCustomArgs);
        reads2 = new ProcessBuilderWrapper(command2, bin);
        reads2.setThreads(threadsToUse);
        reads2.startProcess(null, System.err);
        if (!reads2.isAlive()) throw new ProcessException("BWA aln", reads2.getExitState());
      }
      File file2 = new File(getFileName(tmpdir, taskId, false, 2));
      if (!file2.exists()) {
        file2.createNewFile();
      }
      fastqFile2 = new BufferedWriter(new FileWriter(file2.getAbsoluteFile()));
    }
  }
  // We read the repositories from the file:
  //
  public boolean readData() throws KettleException {
    // Clear the information
    //
    clear();

    File file = new File(getKettleLocalRepositoriesFile());
    if (!file.exists() || !file.isFile()) {
      log.logDetailed(
          BaseMessages.getString(
              PKG, "RepositoryMeta.Log.NoRepositoryFileInLocalDirectory", file.getAbsolutePath()));
      file = new File(getKettleUserRepositoriesFile());
      if (!file.exists() || !file.isFile()) {
        return true; // nothing to read!
      }
    }

    log.logBasic(
        BaseMessages.getString(PKG, "RepositoryMeta.Log.ReadingXMLFile", file.getAbsoluteFile()));

    DocumentBuilderFactory dbf;
    DocumentBuilder db;
    Document doc;

    try {
      // Check and open XML document
      dbf = DocumentBuilderFactory.newInstance();
      db = dbf.newDocumentBuilder();
      try {
        doc = db.parse(file);
      } catch (FileNotFoundException ef) {
        InputStream is =
            getClass().getResourceAsStream("/org/pentaho/di/repository/repositories.xml");
        if (is != null) {
          doc = db.parse(is);
        } else {
          throw new KettleException(
              BaseMessages.getString(
                  PKG, "RepositoryMeta.Error.OpeningFile", file.getAbsoluteFile()),
              ef);
        }
      }
      parseRepositoriesDoc(doc);
    } catch (Exception e) {
      throw new KettleException(BaseMessages.getString(PKG, "RepositoryMeta.Error.ReadingInfo"), e);
    }

    return true;
  }
  public boolean build() throws IOException {
    settingsFile = File.createTempFile("libgdx-setup-settings", ".gradle");
    buildFile = File.createTempFile("libgdx-setup-build", ".gradle");
    if (!settingsFile.exists()) {
      settingsFile.createNewFile();
    }
    if (!buildFile.exists()) {
      buildFile.createNewFile();
    }
    settingsFile.setWritable(true);
    buildFile.setWritable(true);
    try {
      FileWriter settingsWriter = new FileWriter(settingsFile.getAbsoluteFile());
      BufferedWriter settingsBw = new BufferedWriter(settingsWriter);
      String settingsContents = "include ";
      for (ProjectType module : modules) {
        settingsContents += "'" + module.getName() + "'";
        if (modules.indexOf(module) != modules.size() - 1) {
          settingsContents += ", ";
        }
      }
      settingsBw.write(settingsContents);
      settingsBw.close();
      settingsWriter.close();

      FileWriter buildWriter = new FileWriter(buildFile.getAbsoluteFile());
      BufferedWriter buildBw = new BufferedWriter(buildWriter);

      BuildScriptHelper.addBuildScript(modules, buildBw);
      BuildScriptHelper.addAllProjects(buildBw);
      for (ProjectType module : modules) {
        BuildScriptHelper.addProject(module, dependencies, buildBw);
      }

      // Add task here for now
      buildBw.write("\n");
      buildBw.write("tasks.eclipse.doLast {\n");
      buildBw.write("    delete \".project\"\n");
      buildBw.write("}");

      buildBw.close();
      buildWriter.close();
      return true;
    } catch (IOException e) {
      e.printStackTrace();
      return false;
    }
  }
  /**
   * This is a very simple pipeline
   *
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    if (args.length < 3) {
      System.out.println("Training perceptron Usage:");
      System.out.println("args[0]: source dir of training data");
      System.out.println("args[1]: file list of training data");
      System.out.println("args[2]: model file to be saved");
      System.out.println("args[3+]: controller arguments");
      System.exit(-1);
    }

    File srcDir = new File(args[0]);
    File trainingFileList = new File(args[1]);
    File modelFile = new File(args[2]);

    // set settings
    Controller controller = new Controller();
    if (args.length > 3) {
      String[] settings = Arrays.copyOfRange(args, 3, args.length);
      controller.setValueFromArguments(settings);
    }
    System.out.println(controller.toString());

    // train model
    TriggerClassifierTraining trainer = new TriggerClassifierTraining();
    Classifier model = trainer.trainClassifier(srcDir, trainingFileList, modelFile, controller);

    // print out weights or any other detail
    PrintStream out = new PrintStream(modelFile.getAbsoluteFile() + ".weights");
    printFeatureWeights((MaxEnt) model, out);
    out.close();
  }
  @Test(timeout = 2000)
  public void testCleanupQueueClosesFilesystem()
      throws IOException, InterruptedException, NoSuchFieldException, IllegalAccessException {
    Configuration conf = new Configuration();
    File file = new File("afile.txt");
    file.createNewFile();
    Path path = new Path(file.getAbsoluteFile().toURI());

    FileSystem.get(conf);
    Assert.assertEquals(1, getFileSystemCacheSize());

    // With UGI, should close FileSystem
    CleanupQueue cleanupQueue = new CleanupQueue();
    PathDeletionContext context =
        new PathDeletionContext(path, conf, UserGroupInformation.getLoginUser(), null, null);
    cleanupQueue.addToQueue(context);

    while (getFileSystemCacheSize() > 0) {
      Thread.sleep(100);
    }

    file.createNewFile();
    FileSystem.get(conf);
    Assert.assertEquals(1, getFileSystemCacheSize());

    // Without UGI, should not close FileSystem
    context = new PathDeletionContext(path, conf);
    cleanupQueue.addToQueue(context);

    while (file.exists()) {
      Thread.sleep(100);
    }
    Assert.assertEquals(1, getFileSystemCacheSize());
  }
Example #28
0
 /**
  * The ActionListener implementation
  *
  * @param event the event.
  */
 public void actionPerformed(ActionEvent event) {
   String searchText = textField.getText().trim();
   if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) {
     textPane.setText("Blank search text is not allowed for large IdTables.");
   } else {
     File outputFile = null;
     if (saveAs.isSelected()) {
       outputFile = chooser.getSelectedFile();
       if (outputFile != null) {
         String name = outputFile.getName();
         int k = name.lastIndexOf(".");
         if (k != -1) name = name.substring(0, k);
         name += ".txt";
         File parent = outputFile.getAbsoluteFile().getParentFile();
         outputFile = new File(parent, name);
         chooser.setSelectedFile(outputFile);
       }
       if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0);
       outputFile = chooser.getSelectedFile();
     }
     textPane.setText("");
     Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile);
     searcher.start();
   }
 }
Example #29
0
  /**
   * Takes screenshot and adds it to TestNG report.
   *
   * @param driver WebDriver instance.
   */
  public void makeScreenshot(WebDriver driver, String screenshotName) {

    WebDriver augmentedDriver = new Augmenter().augment(driver);

    /* Take a screenshot */
    File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
    String nameWithExtention = screenshotName + ".png";

    /* Copy screenshot to specific folder */
    try {
      /*String reportFolder = "target" + File.separator
      + "failsafe-reports" + File.separator + "firefox"
      + File.separator; */
      String reportFolder = "test-output" + File.separator;
      String screenshotsFolder = "screenshots";
      File screenshotFolder = new File(reportFolder + screenshotsFolder);
      if (!screenshotFolder.getAbsoluteFile().exists()) {
        screenshotFolder.mkdir();
      }
      FileUtils.copyFile(
          screenshot,
          new File(screenshotFolder + File.separator + nameWithExtention).getAbsoluteFile());

    } catch (IOException e) {
      this.log("Failed to capture screenshot: " + e.getMessage());
    }

    log(getScreenshotLink(nameWithExtention, nameWithExtention)); // add
    // screenshot
    // link
    // to
    // the
    // report
  }
Example #30
0
  public String readFromFile(String fileName) {
    StringBuilder sb = new StringBuilder();
    try {
      if (exists(fileName) == false) { // todo - исправь это плиз, а то выебу DONE
        throw new FileNotFoundException();
      } else {

        File file = new File(String.valueOf(fileName));
        String s;

        try {
          BufferedReader bufferedReaderIn =
              new BufferedReader(new FileReader(file.getAbsoluteFile()));
          try {
            while ((s = bufferedReaderIn.readLine()) != null) {
              sb.append(s).append(" ");
            }
          } finally {
            bufferedReaderIn.close();
          }
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    } catch (FileNotFoundException e) {
      log.error("File not found");
    }

    return sb.toString();
  }