Java Code Examples for org.apache.cxf.helpers.FileUtils#createTempFile()

The following examples show how to use org.apache.cxf.helpers.FileUtils#createTempFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCodegenMojo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private String[] createForkOnceArgs(List<List<String>> wargs) throws MojoExecutionException {
    try {
        File f = FileUtils.createTempFile("cxf-w2j", "args");
        PrintWriter fw = new PrintWriter(new FileWriter(f));
        for (List<String> args : wargs) {
            fw.println(Integer.toString(args.size()));
            for (String s : args) {
                fw.println(s);
            }
        }
        fw.println("-1");
        fw.close();
        return new String[] {
            f.getAbsolutePath()
        };
    } catch (IOException ex) {
        throw new MojoExecutionException("Could not create argument file", ex);
    }
}
 
Example 2
Source File: AbstractCodeGeneratorMojo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private String[] createForkOnceArgs(List<List<String>> wargs) throws MojoExecutionException {
    try {
        File f = FileUtils.createTempFile("cxf-w2j", "args");
        PrintWriter fw = new PrintWriter(new FileWriter(f));
        for (List<String> args : wargs) {
            fw.println(Integer.toString(args.size()));
            for (String s : args) {
                fw.println(s);
            }
        }
        fw.println("-1");
        fw.close();
        return new String[] {f.getAbsolutePath()};
    } catch (IOException ex) {
        throw new MojoExecutionException("Could not create argument file", ex);
    }
}
 
Example 3
Source File: HWSAXSourcePayloadProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
private File getSOAPBodyFile(Document doc) throws Exception {
    File file = FileUtils.createTempFile("cxf-systest", "xml");
    try (FileOutputStream out = new FileOutputStream(file)) {
        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
        StaxUtils.writeDocument(doc, writer, true);
        writer.close();
        return file;
    }
}
 
Example 4
Source File: JAXBUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Create the jaxb binding file to customize namespace to package mapping
 *
 * @param namespace
 * @param pkgName
 * @return file
 */
public static File getPackageMappingSchemaBindingFile(String namespace, String pkgName) {
    Document doc = DOMUtils.getEmptyDocument();
    Element rootElement = doc.createElementNS(ToolConstants.SCHEMA_URI, "schema");
    rootElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns", ToolConstants.SCHEMA_URI);
    rootElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:jaxb", ToolConstants.NS_JAXB_BINDINGS);
    rootElement.setAttributeNS(ToolConstants.NS_JAXB_BINDINGS, "jaxb:version", "2.0");
    rootElement.setAttributeNS(null, "targetNamespace", namespace);
    Element annoElement = doc.createElementNS(ToolConstants.SCHEMA_URI, "annotation");
    Element appInfo = doc.createElementNS(ToolConstants.SCHEMA_URI, "appinfo");
    Element schemaBindings = doc.createElementNS(ToolConstants.NS_JAXB_BINDINGS, "jaxb:schemaBindings");
    Element pkgElement = doc.createElementNS(ToolConstants.NS_JAXB_BINDINGS, "jaxb:package");
    pkgElement.setAttributeNS(null, "name", pkgName);
    annoElement.appendChild(appInfo);
    appInfo.appendChild(schemaBindings);
    schemaBindings.appendChild(pkgElement);
    rootElement.appendChild(annoElement);
    File tmpFile = null;
    try {
        tmpFile = FileUtils.createTempFile("customzied", ".xsd");
        try (OutputStream out = Files.newOutputStream(tmpFile.toPath())) {
            StaxUtils.writeTo(rootElement, out);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return tmpFile;
}
 
Example 5
Source File: BinaryDataProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
public T readFrom(Class<T> clazz, Type genericType, Annotation[] annotations, MediaType type,
                       MultivaluedMap<String, String> headers, InputStream is)
    throws IOException {
    try {
        if (InputStream.class.isAssignableFrom(clazz)) {
            if (DigestInputStream.class.isAssignableFrom(clazz)) {
                is = new MessageDigestInputStream(is);
            }
            return clazz.cast(is);
        }
        if (Reader.class.isAssignableFrom(clazz)) {
            return clazz.cast(new InputStreamReader(is, getEncoding(type)));
        }
        if (byte[].class.isAssignableFrom(clazz)) {
            return clazz.cast(IOUtils.readBytesFromStream(is));
        }
        if (File.class.isAssignableFrom(clazz)) {
            LOG.warning("Reading data into File objects with the help of pre-packaged"
                + " providers is not recommended - use InputStream or custom File reader");
            // create a temp file, delete on exit
            File f = FileUtils.createTempFile("File" + UUID.randomUUID().toString(),
                                              "jaxrs",
                                              null,
                                              true);
            OutputStream os = Files.newOutputStream(f.toPath());
            IOUtils.copy(is, os, bufferSize);
            os.close();
            return clazz.cast(f);
        }
        if (StreamingOutput.class.isAssignableFrom(clazz)) {
            return clazz.cast(new ReadingStreamingOutput(is));
        }
    } catch (ClassCastException e) {
        String msg = "Unsupported class: " + clazz.getName();
        LOG.warning(msg);
        throw ExceptionUtils.toInternalServerErrorException(null, null);
    }
    throw new IOException("Unrecognized class");
}
 
Example 6
Source File: Compiler.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void checkLongClasspath(String classpath, List<String> list, int classpathIdx) {
    if (isLongClasspath(classpath)) {
        try {
            classpathTmpFile = FileUtils.createTempFile("cxf-compiler-classpath", null);
            try (PrintWriter out = new PrintWriter(new FileWriter(classpathTmpFile))) {
                out.println(classpath);
                out.flush();
            }
            list.set(classpathIdx + 1, "@" + classpathTmpFile);
        } catch (IOException e) {
            System.err.print("[ERROR] can't write long classpath to @argfile");
        }
    }
}
 
Example 7
Source File: CachedOutputStream.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void createFileOutputStream() throws IOException {
    if (tempFileFailed) {
        return;
    }
    ByteArrayOutputStream bout = (ByteArrayOutputStream)currentStream;
    try {
        if (outputDir == null) {
            tempFile = FileUtils.createTempFile("cos", "tmp");
        } else {
            tempFile = FileUtils.createTempFile("cos", "tmp", outputDir, false);
        }

        currentStream = createOutputStream(tempFile);
        bout.writeTo(currentStream);
        inmem = false;
        streamList.add(currentStream);
    } catch (Exception ex) {
        //Could be IOException or SecurityException or other issues.
        //Don't care what, just keep it in memory.
        tempFileFailed = true;
        if (currentStream != bout) {
            currentStream.close();
        }
        deleteTempFile();
        inmem = true;
        currentStream = bout;
    }
}
 
Example 8
Source File: CachedWriter.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void createFileOutputStream() throws IOException {
    if (tempFileFailed) {
        return;
    }
    LoadingCharArrayWriter bout = (LoadingCharArrayWriter)currentStream;
    try {
        if (outputDir == null) {
            tempFile = FileUtils.createTempFile("cos", "tmp");
        } else {
            tempFile = FileUtils.createTempFile("cos", "tmp", outputDir, false);
        }
        currentStream = createOutputStreamWriter(tempFile);
        bout.writeTo(currentStream);
        inmem = false;
        streamList.add(currentStream);
    } catch (Exception ex) {
        //Could be IOException or SecurityException or other issues.
        //Don't care what, just keep it in memory.
        tempFileFailed = true;
        if (currentStream != bout) {
            currentStream.close();
        }
        deleteTempFile();
        inmem = true;
        currentStream = bout;
    }
}