Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Base64编码字节数组到javax.activation.DataHandler_Java_Axis2 - Fatal编程技术网

Java Base64编码字节数组到javax.activation.DataHandler

Java Base64编码字节数组到javax.activation.DataHandler,java,axis2,Java,Axis2,我编写了一个方法,将给定的PDF文件编码为字节数组: public static byte[] encodeFileToBase64(String pathToPdfFile) throws IOException { File file = new File(pathToPdfFile); InputStream input = null; try { input = new FileInputStream(file); } c

我编写了一个方法,将给定的PDF文件编码为字节数组:

public static byte[] encodeFileToBase64(String pathToPdfFile)
        throws IOException {
    File file = new File(pathToPdfFile);

    InputStream input = null;
    try {
        input = new FileInputStream(file);
    } catch (FileNotFoundException e) {
        throw (e);
    }

    byte[] buffer = new byte[(int) file.length()];
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    int bytesRead;
    try {
        while ((bytesRead = input.read(buffer)) != -1) {
            baos.write(buffer, 0, bytesRead);
        }
    } catch (IOException e) {
        throw (e);
    }

    input.close();
    return baos.toByteArray();
}
现在我正在实现一个SOAP Web服务的接口

用户手册要求使用Base64编码的PDF文件

我使用ApacheAxis2(
wsdl2java
)从给定的
wsdl
文件生成了Java代码。在此代码中,需要将给定的PDF文件设置为
javax.activation.DataHandler

/**
 * Auto generated setter method
 * @param param PdfDocument
 */
public void setPdfDocument(javax.activation.DataHandler param) {
    this.localPdfDocument = param;
}
现在,我的问题是,如何将Base64编码的内容放入
数据处理程序中

你能帮我吗

谢谢大家!

试试这个:

DataSource fds = new FileDataSource("filePath");
request.setMessageFile(new DataHandler(fds));
activation.*包以本机方式处理base64编码