Пример #1
1
  /** @see java.net.URLStreamHandler#openConnection(URL) */
  protected URLConnection openConnection(URL u) throws IOException {

    try {

      URL otherURL = new URL(u.getFile());
      String host = otherURL.getHost();
      String protocol = otherURL.getProtocol();
      int port = otherURL.getPort();
      String file = otherURL.getFile();
      String query = otherURL.getQuery();
      // System.out.println("Trying to load: " + u.toExternalForm());
      String internalFile = null;
      if (file.indexOf("!/") != -1) {
        internalFile = file.substring(file.indexOf("!/") + 2);
        file = file.substring(0, file.indexOf("!/"));
      }
      URL subURL = new URL(protocol, host, port, file);
      File newFile;
      if (cacheList.containsKey(subURL.toExternalForm())) {
        newFile = cacheList.get(subURL.toExternalForm());
      } else {
        InputStream is = (InputStream) subURL.getContent();
        String update = subURL.toExternalForm().replace(":", "_");
        update = update.replace("/", "-");
        File f = File.createTempFile("pack", update);
        f.deleteOnExit();
        FileOutputStream fostream = new FileOutputStream(f);
        copyStream(new BufferedInputStream(is), fostream);

        // Unpack
        newFile = File.createTempFile("unpack", update);
        newFile.deleteOnExit();
        fostream = new FileOutputStream(newFile);
        BufferedOutputStream bos = new BufferedOutputStream(fostream, 50 * 1024);
        JarOutputStream jostream = new JarOutputStream(bos);
        Unpacker unpacker = Pack200.newUnpacker();
        long start = System.currentTimeMillis();

        unpacker.unpack(f, jostream);
        printMessage(
            "Unpack of " + update + " took " + (System.currentTimeMillis() - start) + "ms");
        jostream.close();
        fostream.close();
        cacheList.put(subURL.toExternalForm(), newFile);
      }
      if (internalFile != null) {

        URL directoryURL = new URL("jar:" + newFile.toURL().toExternalForm() + "!/" + internalFile);
        printMessage("Using DirectoryURL:" + directoryURL);
        return directoryURL.openConnection();
      } else return newFile.toURL().openConnection();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    printMessage("Returning null for: " + u.toExternalForm());
    return null;
  }
  @Test
  public void shouldSendMessageWithFileSystemTemplate()
      throws EmailException, MessagingException, IOException {
    final File tempFile = File.createTempFile("dummy", "tmp");
    final File tempDir = tempFile.getParentFile();
    tempFile.deleteOnExit();

    final File testTemplate = new File(tempDir, "testtemplate.vm");
    testTemplate.deleteOnExit();

    final FileWriter out = new FileWriter(testTemplate);
    out.write("<p>Now is the winter of our $item</p>\n");
    out.close();

    unit.setTemplateDirectory(tempDir.getAbsolutePath());

    when(mailSender.createMimeMessage()).thenReturn(mimeMessage);

    final Map<String, Object> templateProperties = new HashMap<String, Object>();
    templateProperties.put("item", "discontent");

    unit.send(
        TO_EXAMPLE, FROM_ADDRESS_DEFAULT, SUBJECT_DEFAULT, "testtemplate", templateProperties);

    verify(mailSender).send(mimeMessage);
    verifyExpectationsForMimeMessage(
        FROM_ADDRESS_DEFAULT,
        SUBJECT_DEFAULT,
        "<p>Now is the winter of our discontent</p>\n",
        TO_EXAMPLE);
  }
Пример #3
0
  /**
   * tests case when Main-Class is not in the zip launched but in another zip referenced by
   * Class-Path
   *
   * @throws Exception in case of troubles
   */
  public void test_main_class_in_another_zip() throws Exception {
    File fooZip = File.createTempFile("hyts_", ".zip");
    File barZip = File.createTempFile("hyts_", ".zip");
    fooZip.deleteOnExit();
    barZip.deleteOnExit();

    // create the manifest
    Manifest man = new Manifest();
    Attributes att = man.getMainAttributes();
    att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
    att.put(Attributes.Name.CLASS_PATH, fooZip.getName());

    File resources = Support_Resources.createTempFolder();

    ZipOutputStream zoutFoo = new ZipOutputStream(new FileOutputStream(fooZip));
    zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class"));
    zoutFoo.write(getResource(resources, "hyts_Foo.ser"));
    zoutFoo.close();

    ZipOutputStream zoutBar = new ZipOutputStream(new FileOutputStream(barZip));
    zoutBar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
    man.write(zoutBar);

    zoutBar.putNextEntry(new ZipEntry("foo/bar/execjartest/Bar.class"));
    zoutBar.write(getResource(resources, "hyts_Bar.ser"));
    zoutBar.close();

    String[] args = new String[] {"-jar", barZip.getAbsolutePath()};

    // execute the JAR and read the result
    String res = Support_Exec.execJava(args, null, false);

    assertTrue("Error executing JAR : result returned was incorrect.", res.startsWith("FOOBAR"));
  }
Пример #4
0
  @Test
  public void testDoNotFixReverseComplementedIndels() {
    final File liftOutputFile = new File(OUTPUT_DATA_PATH, "lift-delete-me.vcf");
    final File rejectOutputFile = new File(OUTPUT_DATA_PATH, "reject-delete-me.vcf");
    final File input = new File(TEST_DATA_PATH, "testLiftover.vcf");

    liftOutputFile.deleteOnExit();
    rejectOutputFile.deleteOnExit();

    final String[] args =
        new String[] {
          "INPUT=" + input.getAbsolutePath(),
          "OUTPUT=" + liftOutputFile.getAbsolutePath(),
          "REJECT=" + rejectOutputFile.getAbsolutePath(),
          "CHAIN=" + CHAIN_FILE,
          "REFERENCE_SEQUENCE=" + REFERENCE_FILE,
          "CREATE_INDEX=false"
        };
    Assert.assertEquals(runPicardCommandLine(args), 0);

    final VCFFileReader liftReader = new VCFFileReader(liftOutputFile, false);
    for (final VariantContext inputContext : liftReader) {
      Assert.fail("there should be no passing indels in the liftover");
    }
    final VCFFileReader rejectReader = new VCFFileReader(rejectOutputFile, false);
    int counter = 0;
    for (final VariantContext inputContext : rejectReader) {
      counter++;
    }
    Assert.assertEquals(counter, 2, "the wrong number of rejected indels faile the liftover");
  }
Пример #5
0
  private List<File> compileClass(Class<?> cls) throws IOException {
    String fileName = cls.getName();
    int end = fileName.indexOf('$');
    if (end != -1) {
      fileName = fileName.substring(0, end);
    }
    fileName = fileName.replace('.', '/') + ".java";
    File file = new File(TEST_DIRECTORY, fileName);
    if (!file.exists()) {
      file = new File(TEST_DIRECTORY2, fileName);
    }
    assertThat("Test source file not found: " + fileName, file.exists(), is(true));
    List<File> compileFileList = Collections.singletonList(file);

    File outTmp = createTempDir("jadx-tmp-classes");
    outTmp.deleteOnExit();
    List<File> files = StaticCompiler.compile(compileFileList, outTmp, withDebugInfo);
    // remove classes which are parents for test class
    Iterator<File> iterator = files.iterator();
    while (iterator.hasNext()) {
      File next = iterator.next();
      if (!next.getName().contains(cls.getSimpleName())) {
        iterator.remove();
      }
    }
    for (File clsFile : files) {
      clsFile.deleteOnExit();
    }
    return files;
  }
Пример #6
0
  @Test
  public void testMoveFromLocalMultiAndDir() throws Exception {
    String name1 = UUID.randomUUID() + "-1.txt";
    String name2 = UUID.randomUUID() + "-2.txt";
    String dst = "local/";
    File f1 = new File(name1);
    File f2 = new File(name2);
    f1.deleteOnExit();
    f2.deleteOnExit();
    FileCopyUtils.copy(name1, new FileWriter(f1));
    FileCopyUtils.copy(name2, new FileWriter(f2));

    try {
      shell.moveFromLocal(name1, dst);
      shell.moveFromLocal(name2, dst);
      assertTrue(shell.test(dst + name1));
      assertTrue(shell.test(dst + name2));
      assertEquals(name1, shell.cat(dst + name1).toString());
      assertEquals(name2, shell.cat(dst + name2).toString());
      assertFalse(f1.exists());
      assertFalse(f2.exists());
    } finally {
      f1.delete();
      f2.delete();
    }
  }
Пример #7
0
  @Test
  public void testBamIntegers() throws IOException {
    final List<String> errorMessages = new ArrayList<String>();
    final SamReader bamReader = SamReaderFactory.makeDefault().open(BAM_INPUT);
    final File bamOutput = File.createTempFile("test", ".bam");
    final File samOutput = File.createTempFile("test", ".sam");
    final SAMFileWriter samWriter =
        new SAMFileWriterFactory().makeWriter(bamReader.getFileHeader(), true, samOutput, null);
    final SAMFileWriter bamWriter =
        new SAMFileWriterFactory().makeWriter(bamReader.getFileHeader(), true, bamOutput, null);
    final SAMRecordIterator iterator = bamReader.iterator();
    while (iterator.hasNext()) {
      try {
        final SAMRecord rec = iterator.next();
        samWriter.addAlignment(rec);
        bamWriter.addAlignment(rec);
      } catch (final Throwable e) {
        System.out.println(e.getMessage());
        errorMessages.add(e.getMessage());
      }
    }

    CloserUtil.close(bamReader);
    samWriter.close();
    bamWriter.close();
    Assert.assertEquals(errorMessages.size(), 0);
    bamOutput.deleteOnExit();
    samOutput.deleteOnExit();
  }
Пример #8
0
  private File createCloudConfigurationZipFile() throws CLIStatusException, IOException {
    if (this.cloudConfiguration == null) {
      return null;
    }

    if (!this.cloudConfiguration.exists()) {
      throw new CLIStatusException(
          "cloud_configuration_file_not_found", this.cloudConfiguration.getAbsolutePath());
    }

    // create a temp file in a temp directory
    final File tempDir = File.createTempFile("__Cloudify_Cloud_configuration", ".tmp");
    FileUtils.forceDelete(tempDir);
    tempDir.mkdirs();

    final File tempFile =
        new File(tempDir, CloudifyConstants.SERVICE_CLOUD_CONFIGURATION_FILE_NAME);

    // mark files for deletion on JVM exit
    tempFile.deleteOnExit();
    tempDir.deleteOnExit();

    if (this.cloudConfiguration.isDirectory()) {
      ZipUtils.zip(this.cloudConfiguration, tempFile);
    } else if (this.cloudConfiguration.isFile()) {
      ZipUtils.zipSingleFile(this.cloudConfiguration, tempFile);
    } else {
      throw new IOException(this.cloudConfiguration + " is neither a file nor a directory");
    }

    return tempFile;
  }
  @Test
  public void testHTTPResultDefaultRows() throws IOException {
    File localFileForUpload = getInputFile("existingFile1", ".tmp");
    File tempFileForDownload = File.createTempFile("downloadedFile1", ".tmp");
    localFileForUpload.deleteOnExit();
    tempFileForDownload.deleteOnExit();

    Object[] r =
        new Object[] {
          HTTP_SERVER_BASEURL + "/uploadFile",
          localFileForUpload.getCanonicalPath(),
          tempFileForDownload.getCanonicalPath()
        };
    RowMeta rowMetaDefault = new RowMeta();
    rowMetaDefault.addValueMeta(new ValueMetaString("URL"));
    rowMetaDefault.addValueMeta(new ValueMetaString("UPLOAD"));
    rowMetaDefault.addValueMeta(new ValueMetaString("DESTINATION"));
    List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
    rows.add(new RowMetaAndData(rowMetaDefault, r));
    Result previousResult = new Result();
    previousResult.setRows(rows);

    JobEntryHTTP http = new JobEntryHTTP();
    http.setParentJob(new Job());
    http.setRunForEveryRow(true);
    http.setAddFilenameToResult(false);
    http.execute(previousResult, 0);
    assertTrue(FileUtils.contentEquals(localFileForUpload, tempFileForDownload));
  }
Пример #10
0
  @Test
  public void test() throws IOException {
    URL resource = getClass().getClassLoader().getResource("GeoIpTestData");
    File path = new File(resource.getPath());
    File tmp = File.createTempFile("compressed", ".db");
    File tmpDir = Files.createTempDir();
    tmp.deleteOnExit();
    tmpDir.deleteOnExit();
    GeoIpCompressor.compress(path, tmp);
    GeoIpCompressor.decompress(tmp, tmpDir);

    List<Location> got = readLocationCSV(new File(tmpDir, "lantern-location.csv"));
    List<Location> expected = readLocationCSV(new File(path, "lantern-location-expected.csv"));
    assertEquals(got.size(), expected.size());
    for (int i = 0; i < got.size(); ++i) {
      Location gotLoc = got.get(i);
      Location expectedLoc = expected.get(i);
      assertEquals(expectedLoc.country, gotLoc.country);
      assertTrue(Math.abs(expectedLoc.latitude - gotLoc.latitude) < 1);
      assertTrue(Math.abs(expectedLoc.longitude - gotLoc.longitude) < 1);
    }

    List<Block> gotBlocks = readBlocksCSV(new File(tmpDir, "lantern-blocks.csv"));
    List<Block> expectedBlocks = readBlocksCSV(new File(path, "lantern-blocks-expected.csv"));
    assertEquals(expectedBlocks, gotBlocks);
  }
Пример #11
0
 /**
  * Creates the temporary folders in parameters and returns <code>true</code> if it was successful.
  */
 private static boolean createTemporaryFolders(File temporaryFolder) {
   // Inspired from java.io.File#mkdirs
   if (temporaryFolder.exists()) {
     return false;
   }
   if (temporaryFolder.mkdir()) {
     temporaryFolder.deleteOnExit();
     return true;
   }
   File canonicalFile = null;
   try {
     canonicalFile = temporaryFolder.getCanonicalFile();
   } catch (IOException e) {
     return false;
   }
   File parent = canonicalFile.getParentFile();
   if (parent != null
       && (createTemporaryFolders(parent) || parent.exists())
       && canonicalFile.mkdir()) {
     temporaryFolder.deleteOnExit();
     return true;
   } else {
     return false;
   }
 }
  @BeforeTest
  void setupBuilder() throws IOException {
    tempSamFileChrM_O = File.createTempFile("CollectGcBias", ".bam", TEST_DIR);
    tempSamFileAllChr = File.createTempFile("CollectGcBias", ".bam", TEST_DIR);
    tempSamFileChrM_O.deleteOnExit();
    tempSamFileAllChr.deleteOnExit();

    final File tempSamFileUnsorted = File.createTempFile("CollectGcBias", ".bam", TEST_DIR);
    tempSamFileUnsorted.deleteOnExit();

    final SAMFileHeader header = new SAMFileHeader();

    try {
      header.setSequenceDictionary(SAMSequenceDictionaryExtractor.extractDictionary(dict));
      header.setSortOrder(SAMFileHeader.SortOrder.unsorted);
    } catch (final SAMException e) {
      e.printStackTrace();
    }

    // build different levels to put into the same bam file for testing multi level collection
    setupTest1(
        1,
        readGroupId1,
        readGroupRecord1,
        sample1,
        library1,
        header,
        setBuilder1); // Sample 1, Library 1, RG 1
    setupTest1(
        2,
        readGroupId2,
        readGroupRecord2,
        sample1,
        library2,
        header,
        setBuilder2); // Sample 1, Library 2, RG 2
    setupTest1(
        3,
        readGroupId3,
        readGroupRecord3,
        sample2,
        library3,
        header,
        setBuilder3); // Sample 2, Library 3, RG 3

    // build one last readgroup for comparing that window count stays the same whether you use all
    // contigs or not
    setupTest2(1, readGroupId1, readGroupRecord1, sample1, library1, header, setBuilder4);

    final List<SAMRecordSetBuilder> test1Builders = new ArrayList<SAMRecordSetBuilder>();
    test1Builders.add(setBuilder1);
    test1Builders.add(setBuilder2);
    test1Builders.add(setBuilder3);

    final List<SAMRecordSetBuilder> test2Builders = new ArrayList<SAMRecordSetBuilder>();
    test2Builders.add(setBuilder4);

    tempSamFileChrM_O = build(test1Builders, tempSamFileUnsorted, header);
    tempSamFileAllChr = build(test2Builders, tempSamFileUnsorted, header);
  }
  /**
   * Create a working, portable runtime of MultiBit in a temporary directory.
   *
   * @return the temporary directory the multibit runtime has been created in
   */
  private File createMultiBitRuntime() throws IOException {
    File multiBitDirectory = FileHandler.createTempDirectory("multibit");
    String multiBitDirectoryPath = multiBitDirectory.getAbsolutePath();

    System.out.println("Building MultiBit runtime in : " + multiBitDirectory.getAbsolutePath());

    // Create an empty multibit.properties.
    File multibitProperties =
        new File(multiBitDirectoryPath + File.separator + "multibit.properties");
    multibitProperties.createNewFile();
    multibitProperties.deleteOnExit();

    // Copy in the blockchain stored in git - this is in source/main/resources/.
    File multibitBlockchain =
        new File(multiBitDirectoryPath + File.separator + "multibit.blockchain");
    FileHandler.copyFile(new File("./src/main/resources/multibit.blockchain"), multibitBlockchain);
    multibitBlockchain.deleteOnExit();

    // Copy in the checkpoints stored in git - this is in source/main/resources/.
    File multibitCheckpoints =
        new File(multiBitDirectoryPath + File.separator + "multibit.checkpoints");
    FileHandler.copyFile(
        new File("./src/main/resources/multibit.checkpoints"), multibitCheckpoints);
    multibitCheckpoints.deleteOnExit();

    return multiBitDirectory;
  }
Пример #14
0
 public void remove(String shapeFile) {
   File folder = shapeFileFolder.folder;
   File shapeFileFolder = new File(folder, shapeFile);
   if (!shapeFileFolder.exists()) return;
   if (!shapeFileFolder.isDirectory()) return;
   for (File file : shapeFileFolder.listFiles()) if (!file.delete()) file.deleteOnExit();
   if (!shapeFileFolder.delete()) shapeFileFolder.deleteOnExit();
 }
Пример #15
0
  /**
   * Install an extension directly into profile location
   *
   * @param extensionURL
   * @param extensionID
   * @param dir
   * @return boolean
   */
  public static boolean installExtension(URL extensionURL, String extensionID, File dir) {
    dir = new File(dir, extensionID);
    if (dir.exists()) {
      return true;
    }
    if (!dir.mkdirs()) {
      return false;
    }

    File file = null;
    InputStream in = null;
    FileOutputStream out = null;
    try {
      file = File.createTempFile("ffe", ".zip"); // $NON-NLS-1$ //$NON-NLS-2$
      in = extensionURL.openStream();
      out = new FileOutputStream(file);
      byte[] buffer = new byte[0x1000];
      int n;
      while ((n = in.read(buffer)) > 0) {
        out.write(buffer, 0, n);
      }
    } catch (IOException e) {
      IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e);
      if (file != null) {
        if (!file.delete()) {
          file.deleteOnExit();
        }
      }
      return false;
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException e) {
        }
      }
      if (out != null) {
        try {
          out.close();
        } catch (IOException e) {
        }
      }
    }

    try {
      ZipUtil.extract(file, dir, null);
    } catch (IOException e) {
      IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e);
      return false;
    } finally {
      if (!file.delete()) {
        file.deleteOnExit();
      }
    }

    return true;
  }
 @After
 public void tearDown() {
   for (File f : myTempDir.listFiles()) {
     f.delete();
     f.deleteOnExit();
   }
   myTempDir.delete();
   myTempDir.deleteOnExit();
 }
Пример #17
0
 public static String getPassivationDir(String rootDir, long testCount, int cacheCount) {
   File dir = new File(rootDir);
   dir = new File(dir, String.valueOf(testCount));
   dir.mkdirs();
   dir.deleteOnExit();
   dir = new File(dir, String.valueOf(cacheCount));
   dir.mkdirs();
   dir.deleteOnExit();
   return dir.getAbsolutePath();
 }
  /**
   * Sets up the SPI instance.
   *
   * @throws Exception Any exception
   */
  @Before
  public void setUp() throws Exception {
    this.configuration = new Properties();
    this.configuration.setProperty(
        "org.fax4j.spi.http.client.class.name", TestHTTPClient.class.getName());
    this.configuration.setProperty(
        "org.fax4j.spi.http.faxjob2request.converter.class.name",
        TemplateFaxJob2HTTPRequestConverter.class.getName());
    this.configuration.setProperty("org.fax4j.spi.http.host.name", "localhost");
    this.configuration.setProperty("org.fax4j.spi.http.port", "80");
    this.configuration.setProperty("org.fax4j.spi.http.ssl", "false");
    this.configuration.setProperty("org.fax4j.spi.http.submit.resource", "${target.name}");
    this.configuration.setProperty(
        "org.fax4j.spi.http.url.parameters",
        "param1=value1&param2=value2&target.name=${target.name}");

    String templateText =
        "target.address=${target.address}\n"
            + "target.name=${target.name}\n"
            + "sender.name=${sender.name}\n"
            + "sender.fax.number=${sender.fax.number}\n"
            + "sender.email=${sender.email}\n"
            + "CONTENT:\n${file}";
    File file = File.createTempFile("submit_fax4j_template_junit", ".txt");
    IOHelper.writeTextFile("submit\n" + templateText, file);
    file.deleteOnExit();
    this.configuration.setProperty(
        "org.fax4j.spi.http.submit.template.url", file.toURI().toURL().toExternalForm());
    file = File.createTempFile("suspend_fax4j_template_junit", ".txt");
    IOHelper.writeTextFile("suspend\n" + templateText, file);
    file.deleteOnExit();
    this.configuration.setProperty(
        "org.fax4j.spi.http.suspend.template.url", file.toURI().toURL().toExternalForm());
    file = File.createTempFile("resume_fax4j_template_junit", ".txt");
    IOHelper.writeTextFile("resume\n" + templateText, file);
    file.deleteOnExit();
    this.configuration.setProperty(
        "org.fax4j.spi.http.resume.template.url", file.toURI().toURL().toExternalForm());
    file = File.createTempFile("cancel_fax4j_template_junit", ".txt");
    IOHelper.writeTextFile("cancel\n" + templateText, file);
    file.deleteOnExit();
    this.configuration.setProperty(
        "org.fax4j.spi.http.cancel.template.url", file.toURI().toURL().toExternalForm());
    file = File.createTempFile("getstatus_fax4j_template_junit", ".txt");
    IOHelper.writeTextFile("getstatus\n" + templateText, file);
    file.deleteOnExit();
    this.configuration.setProperty(
        "org.fax4j.spi.http.get.status.template.url", file.toURI().toURL().toExternalForm());

    this.faxClientSpi =
        (HTTPFaxClientSpi)
            TestUtil.createFaxClientSpi(HTTPFaxClientSpi.class.getName(), this.configuration);
    this.converter =
        (TemplateFaxJob2HTTPRequestConverter) this.faxClientSpi.getFaxJob2HTTPRequestConverter();
  }
  @Override
  protected void doPost() throws IOException {

    String instanceGenerationPrefix =
        Namespaces.getInstanceGenerationPrefix(getInstanceDir(), getGenerationID());
    String outputPathKey = instanceGenerationPrefix + "trees/";
    Store store = Store.get();
    PMML joinedForest = null;

    for (String treePrefix : store.list(outputPathKey, true)) {

      File treeTempFile = File.createTempFile("model-", ".pmml.gz");
      treeTempFile.deleteOnExit();
      store.download(treePrefix, treeTempFile);

      PMML pmml;
      InputStream in = IOUtils.openMaybeDecompressing(treeTempFile);
      try {
        pmml = IOUtil.unmarshal(in);
      } catch (SAXException e) {
        throw new IOException(e);
      } catch (JAXBException e) {
        throw new IOException(e);
      } finally {
        in.close();
      }

      IOUtils.delete(treeTempFile);

      if (joinedForest == null) {
        joinedForest = pmml;
      } else {
        MiningModel existingModel = (MiningModel) joinedForest.getModels().get(0);
        MiningModel nextModel = (MiningModel) pmml.getModels().get(0);
        existingModel
            .getSegmentation()
            .getSegments()
            .addAll(nextModel.getSegmentation().getSegments());
      }
    }

    File tempJoinedForestFile = File.createTempFile("model-", ".pmml.gz");
    tempJoinedForestFile.deleteOnExit();
    OutputStream out = IOUtils.buildGZIPOutputStream(new FileOutputStream(tempJoinedForestFile));
    try {
      IOUtil.marshal(joinedForest, out);
    } catch (JAXBException e) {
      throw new IOException(e);
    } finally {
      out.close();
    }

    store.upload(instanceGenerationPrefix + "model.pmml.gz", tempJoinedForestFile, false);
    IOUtils.delete(tempJoinedForestFile);
  }
Пример #20
0
 public Graph(WeightedBVGraph graph, String[] names) {
   org.apache.log4j.Logger logger =
       org.apache.log4j.Logger.getLogger("it.unimi.dsi.webgraph.ImmutableGraph");
   logger.setLevel(org.apache.log4j.Level.FATAL);
   if (names.length != graph.numNodes())
     throw new Error("Problem with the list of names for the nodes in the graph.");
   try {
     File auxFile = File.createTempFile("graph-maps-" + System.currentTimeMillis(), "aux");
     auxFile.deleteOnExit();
     RecordManager recMan = RecordManagerFactory.createRecordManager(auxFile.getAbsolutePath());
     nodes = recMan.hashMap("nodes");
     nodesReverse = recMan.hashMap("nodesReverse");
   } catch (IOException ex) {
     throw new Error(ex);
   }
   nodes.clear();
   nodesReverse.clear();
   Constructor[] cons = WeightedArc.class.getDeclaredConstructors();
   for (int i = 0; i < cons.length; i++) cons[i].setAccessible(true);
   this.graph = graph;
   WeightedArcSet list = new WeightedArcSet();
   ArcLabelledNodeIterator it = graph.nodeIterator();
   while (it.hasNext()) {
     if (commit++ % COMMIT_SIZE == 0) {
       commit();
       list.commit();
     }
     Integer aux1 = it.nextInt();
     Integer aux2 = null;
     ArcLabelledNodeIterator.LabelledArcIterator suc = it.successors();
     while ((aux2 = suc.nextInt()) != null && aux2 >= 0 && (aux2 < graph.numNodes()))
       try {
         WeightedArc arc = (WeightedArc) cons[0].newInstance(aux2, aux1, suc.label().getFloat());
         list.add(arc);
         this.nodes.put(aux1, names[aux1]);
         this.nodes.put(aux2, names[aux2]);
         this.nodesReverse.put(names[aux1], aux1);
         this.nodesReverse.put(names[aux2], aux2);
       } catch (Exception ex) {
         throw new Error(ex);
       }
   }
   reverse = new WeightedBVGraph(list.toArray(new WeightedArc[0]));
   numArcs = list.size();
   iterator = nodeIterator();
   try {
     File auxFile = File.createTempFile("graph" + System.currentTimeMillis(), "aux");
     auxFile.deleteOnExit();
     String basename = auxFile.getAbsolutePath();
     store(basename);
   } catch (IOException ex) {
     throw new Error(ex);
   }
   commit();
 }
Пример #21
0
  /* ------------------------------------------------------------ */
  @Test
  public void testJarFileCopyToDirectoryTraversal() throws Exception {
    String s = "jar:" + __userURL + "TestData/extract.zip!/";
    Resource r = Resource.newResource(s);

    assertTrue(r instanceof JarResource);
    JarResource jarResource = (JarResource) r;

    File destParent = File.createTempFile("copyjar", null);
    if (destParent.exists()) destParent.delete();
    destParent.mkdir();
    destParent.deleteOnExit();

    File dest = new File(destParent.getCanonicalPath() + "/extract");
    if (dest.exists()) dest.delete();
    dest.mkdir();
    dest.deleteOnExit();

    jarResource.copyTo(dest);

    // dest contains only the valid entry; dest.getParent() contains only the dest directory
    assertEquals(1, dest.listFiles().length);
    assertEquals(1, dest.getParentFile().listFiles().length);

    FilenameFilter dotdotFilenameFilter =
        new FilenameFilter() {
          public boolean accept(File directory, String name) {
            return name.equals("dotdot.txt");
          }
        };
    assertEquals(0, dest.listFiles(dotdotFilenameFilter).length);
    assertEquals(0, dest.getParentFile().listFiles(dotdotFilenameFilter).length);

    FilenameFilter extractfileFilenameFilter =
        new FilenameFilter() {
          public boolean accept(File directory, String name) {
            return name.equals("extract-filenotdir");
          }
        };
    assertEquals(0, dest.listFiles(extractfileFilenameFilter).length);
    assertEquals(0, dest.getParentFile().listFiles(extractfileFilenameFilter).length);

    FilenameFilter currentDirectoryFilenameFilter =
        new FilenameFilter() {
          public boolean accept(File directory, String name) {
            return name.equals("current.txt");
          }
        };
    assertEquals(1, dest.listFiles(currentDirectoryFilenameFilter).length);
    assertEquals(0, dest.getParentFile().listFiles(currentDirectoryFilenameFilter).length);

    IO.delete(dest);
    assertFalse(dest.exists());
  }
 @Before
 public void setUp() {
   String fullSizeImagesDirectoryName = "./target/images/fullsize";
   File fullSizeImagesDirectory = new File(fullSizeImagesDirectoryName);
   fullSizeImagesDirectory.mkdirs();
   fullSizeImagesDirectory.deleteOnExit();
   String thumbnailImagesDirectoryName = "./target/images/thumbnails";
   File thumbnailImagesDirectory = new File(thumbnailImagesDirectoryName);
   thumbnailImagesDirectory.mkdirs();
   thumbnailImagesDirectory.deleteOnExit();
 }
  /////////////////////////////////////////////////////////////////////////////
  // This test checks the functionality of the gc bias code. Compares values from running a
  // generated temporary Sam file through
  // CollectGcBiasMetrics to manually-calculated values.
  /////////////////////////////////////////////////////////////////////////////
  @Test
  public void runGcBiasMultiLevelTest() throws IOException {
    final File outfile = File.createTempFile("test", ".gc_bias_summary_metrics");
    final File detailsOutfile = File.createTempFile("test", ".gc_bias_detail_metrics");
    outfile.deleteOnExit();
    detailsOutfile.deleteOnExit();

    runGcBias(tempSamFileChrM_O, outfile, detailsOutfile);

    final MetricsFile<GcBiasSummaryMetrics, Comparable<?>> output =
        new MetricsFile<GcBiasSummaryMetrics, Comparable<?>>();
    output.read(new FileReader(outfile));

    for (final GcBiasSummaryMetrics metrics : output.getMetrics()) {
      if (metrics.ACCUMULATION_LEVEL.equals("All Reads")) { // ALL_READS level
        Assert.assertEquals(metrics.TOTAL_CLUSTERS, 300);
        Assert.assertEquals(metrics.ALIGNED_READS, 600);
        Assert.assertEquals(metrics.AT_DROPOUT, 21.624498);
        Assert.assertEquals(metrics.GC_DROPOUT, 3.525922);
      } else if (metrics.READ_GROUP != null
          && metrics.READ_GROUP.equals("TestReadGroup1")) { // Library 1
        Assert.assertEquals(metrics.TOTAL_CLUSTERS, 100);
        Assert.assertEquals(metrics.ALIGNED_READS, 200);
        Assert.assertEquals(metrics.AT_DROPOUT, 23.627784);
        Assert.assertEquals(metrics.GC_DROPOUT, 2.582877);
      } else if (metrics.READ_GROUP != null
          && metrics.READ_GROUP.equals("TestReadGroup2")) { // Library 2
        Assert.assertEquals(metrics.TOTAL_CLUSTERS, 100);
        Assert.assertEquals(metrics.ALIGNED_READS, 200);
        Assert.assertEquals(metrics.AT_DROPOUT, 23.784958);
        Assert.assertEquals(metrics.GC_DROPOUT, 4.025922);
      } else if (metrics.READ_GROUP != null
          && metrics.READ_GROUP.equals("TestReadGroup3")) { // Library 3
        Assert.assertEquals(metrics.TOTAL_CLUSTERS, 100);
        Assert.assertEquals(metrics.ALIGNED_READS, 200);
        Assert.assertEquals(metrics.AT_DROPOUT, 21.962578);
        Assert.assertEquals(metrics.GC_DROPOUT, 4.559328);
      } else if (metrics.SAMPLE != null
          && metrics.SAMPLE.equals("TestSample1")) { // Library 1 and 2
        Assert.assertEquals(metrics.TOTAL_CLUSTERS, 200);
        Assert.assertEquals(metrics.ALIGNED_READS, 400);
        Assert.assertEquals(metrics.AT_DROPOUT, 23.194597);
        Assert.assertEquals(metrics.GC_DROPOUT, 3.275922);
      } else if (metrics.SAMPLE != null && metrics.SAMPLE.equals("TestSample2")) { // Library 3
        Assert.assertEquals(metrics.TOTAL_CLUSTERS, 100);
        Assert.assertEquals(metrics.ALIGNED_READS, 200);
        Assert.assertEquals(metrics.AT_DROPOUT, 21.962578);
        Assert.assertEquals(metrics.GC_DROPOUT, 4.559328);
      } else {
        Assert.fail("Unexpected metric: " + metrics);
      }
    }
  }
Пример #24
0
  @Test
  public void testCollision() throws Exception {
    File fileDir = TestUtils.createTempDir();

    File dataFile = new File(fileDir + File.separator + "0_0_0.data");
    dataFile.deleteOnExit();

    FileOutputStream fw = new FileOutputStream(dataFile.getAbsoluteFile());
    DataOutputStream outputStream = new DataOutputStream(fw);

    /*
     * 4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa200a8284bf36e8e4b55b35f427593d849676da0d1555d8360fb5f07fea2
     * and the (different by two bits)
     * 4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa202a8284bf36e8e4b55b35f427593d849676da0d1d55d8360fb5f07fea2
     * both have MD5 hash 008ee33a9d58b51cfeb425b0959121c9
     */

    String[] md5collision = {
      "4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa200a8284bf36e8e4b55b35f427593d849676da0d1555d8360fb5f07fea2",
      "4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa202a8284bf36e8e4b55b35f427593d849676da0d1d55d8360fb5f07fea2"
    };

    outputStream.writeShort(2);
    for (int i = 0; i < 2; i++) {
      String input = md5collision[i];
      byte[] hexInput = ByteUtils.fromHexString(input);
      outputStream.writeInt(hexInput.length);
      outputStream.writeInt(hexInput.length);
      outputStream.write(hexInput);
      outputStream.write(hexInput);
    }
    outputStream.close();
    fw.close();

    File indexFile = new File(fileDir + File.separator + "0_0_0.index");
    indexFile.createNewFile();
    indexFile.deleteOnExit();

    ChunkedFileSet fileSet =
        new ChunkedFileSet(
            fileDir,
            getTempStrategy(),
            NODE_ID,
            VoldemortConfig.DEFAULT_RO_MAX_VALUE_BUFFER_ALLOCATION_SIZE);

    for (int i = 0; i < 2; i++) {
      String input = md5collision[i];
      byte[] hexInput = ByteUtils.fromHexString(input);
      byte[] hexValue = fileSet.readValue(hexInput, 0, 0);
      Assert.assertArrayEquals(hexInput, hexValue);
    }
  }
Пример #25
0
 /**
  * Completely obliterates the given file, leaving no trace of it.
  *
  * @param file
  */
 public static void obliterate(File file) {
   if (file.isFile()) {
     file.delete();
     file.deleteOnExit();
   } else if (file.isDirectory()) {
     // delete everything inside, then delete this on exit
     for (File child : file.listFiles()) {
       obliterate(child);
     }
     file.delete();
     file.deleteOnExit();
   }
 }
Пример #26
0
  /** Plot the currently selected output buffer */
  protected void plotOutput() {
    try {
      StringBuffer sb = m_History.getSelectedBuffer();
      if (sb != null) {
        // dump the output into a temporary file
        File tempDirFile = new File("/tmp");
        final File bufferFile = File.createTempFile("buffer", "", tempDirFile);
        bufferFile.deleteOnExit();

        PrintWriter writer =
            new PrintWriter(new BufferedOutputStream(new FileOutputStream(bufferFile)));
        writer.print(sb);
        writer.close();

        // launch the perl script to process the file

        // Process proc = Runtime.getRuntime().exec("perl weka/gui/experiment/plot.pl " +
        // bufferFile.getPath());
        Process proc =
            Runtime.getRuntime()
                .exec(
                    "perl /u/ml/software/weka-latest/weka/gui/experiment/plot.pl "
                        + bufferFile.getPath());
        proc.waitFor();

        // get a list of generated gnuplot scripts
        String[] scriptList =
            tempDirFile.list(
                new FilenameFilter() {
                  public boolean accept(File f, String s) {
                    return (s.endsWith(".gplot") && s.startsWith(bufferFile.getName()));
                  }
                });
        for (int i = 0; i < scriptList.length; i++) {
          // launch gnuplot
          scriptList[i] = tempDirFile.getPath() + "/" + scriptList[i];
          System.out.println(scriptList[i]);
          proc = Runtime.getRuntime().exec("gnuplot -persist " + scriptList[i]);
          File plotFile = new File(scriptList[i]);
          plotFile.deleteOnExit();
          File dataFile = new File(scriptList[i].replaceAll(".gplot", ".dat"));
          dataFile.deleteOnExit();
        }
      } else {
        m_PlotBut.setEnabled(false);
      }
    } catch (Exception e) {
      System.out.println("Problems plotting: " + e);
      e.printStackTrace();
    }
  }
Пример #27
0
  /* ------------------------------------------------------------ */
  @Test
  public void testJarFile() throws Exception {
    String s = "jar:" + __userURL + "TestData/test.zip!/subdir/";
    Resource r = Resource.newResource(s);

    Set<String> entries = new HashSet<>(Arrays.asList(r.list()));
    assertEquals(3, entries.size());
    assertTrue(entries.contains("alphabet"));
    assertTrue(entries.contains("numbers"));
    assertTrue(entries.contains("subsubdir/"));

    File extract = File.createTempFile("extract", null);
    if (extract.exists()) extract.delete();
    extract.mkdir();
    extract.deleteOnExit();

    r.copyTo(extract);

    Resource e = Resource.newResource(extract.getAbsolutePath());

    entries = new HashSet<>(Arrays.asList(e.list()));
    assertEquals(3, entries.size());
    assertTrue(entries.contains("alphabet"));
    assertTrue(entries.contains("numbers"));
    assertTrue(entries.contains("subsubdir/"));
    IO.delete(extract);

    s = "jar:" + __userURL + "TestData/test.zip!/subdir/subsubdir/";
    r = Resource.newResource(s);

    entries = new HashSet<>(Arrays.asList(r.list()));
    assertEquals(2, entries.size());
    assertTrue(entries.contains("alphabet"));
    assertTrue(entries.contains("numbers"));

    extract = File.createTempFile("extract", null);
    if (extract.exists()) extract.delete();
    extract.mkdir();
    extract.deleteOnExit();

    r.copyTo(extract);

    e = Resource.newResource(extract.getAbsolutePath());

    entries = new HashSet<>(Arrays.asList(e.list()));
    assertEquals(2, entries.size());
    assertTrue(entries.contains("alphabet"));
    assertTrue(entries.contains("numbers"));
    IO.delete(extract);
  }
  @Test
  public void testCreateDefaultSettingsWithProxy() {
    // given
    File settingsXML = new File(Paths.Setting.settingsXMLPath);
    settingsXML.deleteOnExit();

    File installationData = new File(Paths.Setting.installationDataXMLPath);
    installationData.deleteOnExit();

    EnvironmentContext environmentContext = new EnvironmentContext();
    environmentContext.setSettingsXMLPath(Paths.Setting.settingsXMLPath);
    environmentContext.setInstallationDataXMLPath(Paths.Setting.installationDataXMLPath);

    // when
    EnvironmentData environmentData =
        new EnvironmentDataManager(environmentContext).createDefaultSettingsWithProxy();
    ClientSettings clientSettings = environmentData.getClientSettings();
    List<ProgramSettings> programsSettings =
        new ArrayList<ProgramSettings>(environmentData.getProgramsSettings());

    // then
    assertThat(clientSettings)
        .as("createEnvironmentDataWithProxy() should create client's settings")
        .isNotNull();
    assertThat(clientSettings.getPathToClientDirectory())
        .as("createEnvironmentDataWithProxy() should create client's directory")
        .isNotNull()
        .isEqualTo(environmentContext.getDefaultPathToClientDirectory());
    assertThat(clientSettings.getPathToClient())
        .as("createEnvironmentDataWithProxy() should create client's executable")
        .isNotNull()
        .isEqualTo(environmentContext.getDefaultPathToClient());
    assertThat(clientSettings.getPathToInstaller())
        .as("createEnvironmentDataWithProxy() should create installer's path")
        .isNotNull()
        .isEqualTo(environmentContext.getDefaultPathToInstaller());
    assertThat(clientSettings.getProxyAddress())
        .as("createEnvironmentDataWithProxy() should create proxy's address")
        .isNotNull()
        .isEqualTo(environmentContext.getDefaultProxyAddress());
    assertThat(clientSettings.getProxyPort())
        .as("createEnvironmentDataWithProxy() should create proxy's port")
        .isNotNull()
        .isEqualTo(environmentContext.getDefaultProxyPort());

    assertThat(programsSettings)
        .as("createEnvironmentDataWithProxy() should not create any program's settings")
        .isNotNull()
        .isEmpty();
  }
Пример #29
0
  @Test(expected = ResourceException.class)
  public void testMoveDirectoryResourceToFile() throws IOException {
    File file = File.createTempFile("fileresourcetest", ".tmp");
    file.deleteOnExit();
    file.createNewFile();

    File folder = OperatingSystemUtils.createTempDir();
    folder.deleteOnExit();
    folder.mkdir();

    DirectoryResource folderResource = resourceFactory.create(DirectoryResource.class, folder);
    FileResource fileResource = resourceFactory.create(FileResource.class, file);
    folderResource.moveTo(fileResource);
  }
Пример #30
0
 /**
  * 安全删除一个文件或者目录树
  *
  * @param fileOrDir
  */
 public static final void delete(final File fileOrDir) {
   if (!fileOrDir.exists()) return;
   if (fileOrDir.isFile()) {
     fileOrDir.delete();
     fileOrDir.deleteOnExit();
     return;
   }
   final File subFiles[] = fileOrDir.listFiles();
   if (null != subFiles && subFiles.length > 0) {
     for (final File subFile : subFiles) delete(subFile);
   }
   fileOrDir.delete();
   fileOrDir.deleteOnExit();
 }