コード例 #1
0
  public void start() {
    // see initialization of this property in sonar-application
    String driverPath = settings.getString(ProcessProperties.JDBC_DRIVER_PATH);
    if (driverPath == null) {
      // Medium tests
      return;
    }
    File driver = new File(driverPath);
    File deployedDriver = new File(fileSystem.getDeployDir(), driver.getName());
    if (!deployedDriver.exists() || FileUtils.sizeOf(deployedDriver) != FileUtils.sizeOf(driver)) {
      try {
        FileUtils.copyFile(driver, deployedDriver);
      } catch (IOException e) {
        throw new IllegalStateException(
            String.format("Can not copy the JDBC driver from %s to %s", driver, deployedDriver), e);
      }
    }

    File deployedDriverIndex = fileSystem.getDeployedJdbcDriverIndex();
    try {
      FileUtils.writeStringToFile(deployedDriverIndex, driverIndexContent(deployedDriver));
    } catch (IOException e) {
      throw new IllegalStateException("Can not generate index of JDBC driver", e);
    }
  }
コード例 #2
0
ファイル: Xls2xmlConverter.java プロジェクト: cottley/xls2xml
  public void run() {
    String sourceDir = config.getString("source.path");
    String destDir = config.getString("destination.path");
    String sourceFilePath = file.toString();
    Xls2xmlStats.setThreadFileProcess(Thread.currentThread().getName(), sourceFilePath);
    if (isDebugging) {
      log.debug("Processing " + sourceFilePath);
    }
    // Destination file is same directory in output with xml
    String destFilePath = sourceFilePath.substring(sourceDir.length());
    if (destFilePath.startsWith(File.separator)) {
      destFilePath = destFilePath.substring(1);
    }
    // Add extensions with .xml
    destFilePath = destFilePath + ".xml";
    File destFile = new File(destDir, destFilePath);
    destFilePath = destFile.toString();
    try {
      if (ignoreExisting && destFile.exists() && (FileUtils.sizeOf(destFile) > 0)) {
        log.debug("Ignoring the recreation of file: " + destFilePath);
        log.debug("Filesize is: " + FileUtils.sizeOf(destFile));
      } else {
        FileUtils.touch(destFile);

        if (isDebugging) {
          log.debug("Created destination file: " + destFilePath);
        }
        // Put some XML in the file

        String processedXML = process2xml();

        BufferedWriter output = new BufferedWriter(new FileWriter(destFile));

        // Only write data to the file if there is data from the processing
        if (!processedXML.equals("")) {
          output.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
          output.newLine();
          String roottag = config.getString("conversion.tags.root");
          output.append("<" + roottag + ">");
          output.newLine();
          output.append(processedXML);
          output.append("</" + roottag + ">");
        }

        output.close();
      }
    } catch (IOException ioe) {
      log.error("Could not create destination file: " + destFilePath, ioe);
    }

    Xls2xmlStats.recordFileProcessed();
    Xls2xmlStats.setThreadFileProcess(Thread.currentThread().getName(), "");
    log.info("STATISTICS: " + Xls2xmlStats.status());
  }
コード例 #3
0
  @Test
  public void testNewSample() throws IOException, XMLStreamException {
    sampleFile =
        new File(
            PRMS2ParserTest.class
                .getClassLoader()
                .getResource("gov/usgs/cida/watersmart/netcdf/PRMS2_sample.zip")
                .getFile());

    RunMetadata runMeta =
        new RunMetadata(
            ModelType.PRMS2,
            "1",
            "test",
            "1",
            "1",
            "2012-07-10T00:00:00Z",
            "Special",
            "comments",
            "*****@*****.**",
            "http://cida-wiwsc-gdp2qa.er.usgs.gov:8082/geoserver/NWC/ows",
            "NWC:Dense1",
            "site_no");
    CreateDSGFromZip.ReturnInfo info = CreateDSGFromZip.create(sampleFile, runMeta);
    File ncFile = new File("/tmp/prms2/" + info.filename);

    assertThat(info.filename, is(equalTo("PRMS2_sample.nc")));
    assertThat(FileUtils.sizeOf(ncFile), is(equalTo(1101945L)));
    FileUtils.deleteQuietly(ncFile);
  }
コード例 #4
0
ファイル: Xls2xmlConverter.java プロジェクト: cottley/xls2xml
  public void runSingleFile() {
    String destFilePath = "";

    try {

      File destFile = specificDestFile;
      destFilePath = destFile.getCanonicalPath();

      if (ignoreExisting && destFile.exists() && (FileUtils.sizeOf(destFile) > 0)) {
        log.debug("Ignoring the recreation of file: " + destFilePath);
        log.debug("Filesize is: " + FileUtils.sizeOf(destFile));
      } else {
        FileUtils.touch(destFile);

        if (isDebugging) {
          log.debug("Created destination file: " + destFilePath);
        }
        // Put some XML in the file

        String processedXML = process2xml();

        BufferedWriter output = new BufferedWriter(new FileWriter(destFile));

        // Only write data to the file if there is data from the processing
        if (!processedXML.equals("")) {
          output.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
          output.newLine();
          String roottag = config.getString("conversion.tags.root");
          output.append("<" + roottag + ">");
          output.newLine();
          output.append(processedXML);
          output.append("</" + roottag + ">");
        }

        output.close();
      }

    } catch (IOException ioe) {
      log.error("Could not create destination file: " + destFilePath, ioe);
    }
  }
コード例 #5
0
ファイル: FileUtil.java プロジェクト: sara-liu/liferay-portal
  public static void checkFilePath(Path filePath) {

    // Check to see if the file or folder is still being written to. If
    // it is, wait until the process is finished before making any future
    // modifications. This is used to prevent file system interruptions.

    try {
      while (true) {
        long size1 = FileUtils.sizeOf(filePath.toFile());

        Thread.sleep(1000);

        long size2 = FileUtils.sizeOf(filePath.toFile());

        if (size1 == size2) {
          break;
        }
      }
    } catch (Exception e) {
      _logger.error(e.getMessage(), e);
    }
  }
コード例 #6
0
  @Test
  public void testNetCDF() throws IOException, XMLStreamException {
    RunMetadata runMeta =
        new RunMetadata(
            ModelType.PRMS2,
            "1",
            "test",
            "1",
            "1",
            "2012-07-10T00:00:00Z",
            "Special",
            "comments",
            "*****@*****.**",
            "http://cida-wiwsc-gdp2qa.er.usgs.gov:8082/geoserver/NWC/ows",
            "NWC:Dense1",
            "site_no");
    CreateDSGFromZip.ReturnInfo info = CreateDSGFromZip.create(sampleFile, runMeta);
    File ncFile = new File("/tmp/prms2/" + info.filename);

    assertThat(info.filename, is(equalTo("PRMS_2_realupload.nc")));
    assertThat(FileUtils.sizeOf(ncFile), is(equalTo(13935321L)));
    FileUtils.deleteQuietly(ncFile);
  }
コード例 #7
0
 /**
  * 取得文件大小或文件数量
  *
  * @param file
  * @return
  */
 public static long size(File file) {
   return FileUtils.sizeOf(file);
 }