Example usage for java.io File createTempFile

List of usage examples for java.io File createTempFile

Introduction

In this page you can find the example usage for java.io File createTempFile.

Prototype

public static File createTempFile(String prefix, String suffix) throws IOException 

Source Link

Document

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

Usage

From source file:com.centeractive.ws.builder.DefinitionSaveTest.java

public static File getGeneratedFolder(int serviceId) throws WSDLException, IOException {
    URL wsdlUrl = ServiceComplianceTest.getDefinitionUrl(serviceId);
    SoapBuilder builder = new SoapBuilder(wsdlUrl);
    File tempFolder = File.createTempFile("maven-temp", Long.toString(System.nanoTime()));
    if (!tempFolder.delete()) {
        throw new RuntimeException("cannot delete tmp file");
    }//from   w  w  w. jav  a2  s.  c  om
    if (!tempFolder.mkdir()) {
        throw new RuntimeException("cannot create tmp folder");
    }
    String fileName = FilenameUtils.getBaseName(wsdlUrl.toString());
    builder.saveWsdl(fileName, tempFolder);
    tempFolder.deleteOnExit();
    return tempFolder;
}

From source file:au.org.ala.delta.DeltaTestCase.java

/**
 * Makes a copy of the supplied DELTA file and returns a new SlotFile created from the copied file.
 * @param fileName the ClassLoader relative name of the DELTA file.
 * @return a new SlotFile.//w  ww.java 2  s.  c  om
 * @throws IOException if the file cannot be found.
 */
protected SlotFile copyAndOpen(String fileName) throws IOException {

    URL deltaFileUrl = getClass().getResource(fileName);
    File tempDeltaFile = File.createTempFile("test", ".dlt");

    _tempFiles.add(tempDeltaFile);

    FileUtils.copyURLToFile(deltaFileUrl, tempDeltaFile);
    SlotFile slotFile = new SlotFile(tempDeltaFile.getAbsolutePath(), BinFileMode.FM_EXISTING);

    return slotFile;
}

From source file:com.kylinolap.metadata.tool.HiveSourceTableLoader.java

public static Set<String> reloadHiveTables(String[] hiveTables, KylinConfig config) throws IOException {
    Map<String, Set<String>> db2tables = Maps.newHashMap();
    for (String table : hiveTables) {
        int cut = table.indexOf('.');
        String database = cut >= 0 ? table.substring(0, cut).trim() : "DEFAULT";
        String tableName = cut >= 0 ? table.substring(cut + 1).trim() : table.trim();
        Set<String> set = db2tables.get(database);
        if (set == null) {
            set = Sets.newHashSet();/* w w w . j a v  a  2  s .  c  o  m*/
            db2tables.put(database, set);
        }
        set.add(tableName);
    }

    // metadata tmp dir
    File metaTmpDir = File.createTempFile("meta_tmp", null);
    metaTmpDir.delete();
    metaTmpDir.mkdirs();

    for (String database : db2tables.keySet()) {
        for (String table : db2tables.get(database)) {
            TableDesc tableDesc = MetadataManager.getInstance(config).getTableDesc(table);
            if (tableDesc == null) {
                continue;
            }
            if (tableDesc.getDatabase().equalsIgnoreCase(database)) {
                continue;
            } else {
                throw new UnsupportedOperationException(
                        String.format("there is already a table[%s] in database[%s]", tableDesc.getName(),
                                tableDesc.getDatabase()));
            }
        }
    }

    // extract from hive
    Set<String> loadedTables = Sets.newHashSet();
    for (String database : db2tables.keySet()) {
        List<String> loaded = extractHiveTables(database, db2tables.get(database), metaTmpDir, config);
        loadedTables.addAll(loaded);
    }

    // save loaded tables
    ResourceTool.copy(KylinConfig.createInstanceFromUri(metaTmpDir.getAbsolutePath()), config);

    return loadedTables;
}

From source file:com.vmware.photon.controller.api.client.resource.ImagesApiTest.java

@Test
public void testUploadImage() throws IOException {
    File temp = File.createTempFile("temp-image", ".vmdk");
    (new File(temp.getAbsolutePath())).deleteOnExit();

    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);
    ImagesApi imagesApi = new ImagesApi(this.restClient);

    Task task = imagesApi.uploadImage(temp.getAbsolutePath());
    assertEquals(task, responseTask);//from w  ww  .j a va  2  s .c om
}

From source file:com.mgmtp.jfunk.core.util.ScreenCapturerTest.java

@Test(groups = "excludeFromCI")
public void testCaptureScreen() throws IOException {
    testFileOrDir = File.createTempFile("jFunkScreenCapture", ".png");
    ScreenCapturer.captureScreen(testFileOrDir);
    assertThat(testFileOrDir).exists();/*from www  .ja  va2  s.  c om*/
}

From source file:com.intropro.prairie.format.seq.SequenceFormatReader.java

private void copyDataToTmpFile() throws IOException {
    tmpFile = File.createTempFile("seq-", ".dat");
    OutputStream outputStream = new FileOutputStream(tmpFile);
    IOUtils.copy(inputStream, outputStream);
    outputStream.close();/*from w  w w .  jav  a  2  s . c  om*/
    inputStream.close();
}

From source file:com.vmware.photon.controller.api.client.resource.ImagesRestApiTest.java

@Test
public void testUploadImage() throws IOException {
    File temp = File.createTempFile("temp-image", ".vmdk");
    (new File(temp.getAbsolutePath())).deleteOnExit();

    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);
    ImagesApi imagesApi = new ImagesRestApi(this.restClient);

    Task task = imagesApi.uploadImage(temp.getAbsolutePath());
    assertEquals(task, responseTask);/*  w w  w.  j a  va2  s  .  c  om*/
}

From source file:de.nrw.hbz.regal.sync.ingest.DippMapping.java

private String flux(File file, String pid) throws IOException, RecognitionException {
    File outfile = File.createTempFile("lobid", "rdf");
    outfile.deleteOnExit();//from   w  ww .  j a  v a2  s  . c o  m
    System.out.println(
            Thread.currentThread().getContextClassLoader().getResource("dipp-qdc-to-lobid.flux").toString());
    File fluxFile = createFile("dipp-qdc-to-lobid.flux", "/tmp/dipp-qdc-to-lobid.flux");
    createFile("dipp-qdc-to-lobid.xml", "/tmp/dipp-qdc-to-lobid.xml");

    Flux.main(new String[] { fluxFile.getAbsolutePath(), "in=" + file.getAbsolutePath(),
            "out=" + outfile.getAbsolutePath(), "subject=" + pid });
    return FileUtils.readFileToString(outfile).trim();
}

From source file:de.nrw.hbz.regal.sync.ingest.OpusMapping.java

private String flux(File file, String pid) throws IOException, RecognitionException {
    File outfile = File.createTempFile("lobid", "rdf");
    outfile.deleteOnExit();//from  w w  w. j  ava 2  s  .  c om
    File fluxFile = createFile("opus-xmetadissplus-to-lobid.flux", "/tmp/opus-xmetadissplus-to-lobid.flux");
    createFile("opus-xmetadissplus-to-lobid.xml", "/tmp/opus-xmetadissplus-to-lobid.xml");

    Flux.main(new String[] { fluxFile.getAbsolutePath(), "in=" + file.getAbsolutePath(),
            "out=" + outfile.getAbsolutePath(), "subject=" + pid });
    return FileUtils.readFileToString(outfile).trim();
}

From source file:net.big_oh.common.jdbc.event.listener.logger.JDBCFileLoggingListener.java

public JDBCFileLoggingListener(boolean logBeforeEvent, boolean logAfterEvent) {
    super(logBeforeEvent, logAfterEvent);

    try {//from   w w  w .j ava  2 s  .  co  m
        writer = new FileWriter(File.createTempFile(JDBCFileLoggingListener.class.getSimpleName(), ".log"),
                true);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}