All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.directwebremoting.extend.DataUrlDownloadManager Maven / Gradle / Ivy

Go to download

DWR is easy Ajax for Java. It makes it simple to call Java code directly from Javascript. It gets rid of almost all the boilerplate code between the web browser and your Java code. This version 4.0.2 works with Jakarta Servlet 4.0.2.

The newest version!
package org.directwebremoting.extend;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.directwebremoting.io.FileTransfer;
import org.directwebremoting.io.OutputStreamLoader;
import org.directwebremoting.util.Base64;
import org.directwebremoting.util.LocalUtil;

/**
 * A download manager that works my returning a data: URL so the data is
 * sent directly without waiting in some store.
 * 

This method has the benefit that it works in a clustered environment * and is quite simple. However it does not work in IE. * @author Jose Noheda [jose dot noheda at gmail dot com] * @author Joe Walker [joe at getahead dot ltd dot uk] */ public class DataUrlDownloadManager implements DownloadManager { /* (non-Javadoc) * @see org.directwebremoting.extend.DownloadManager#addFile(org.directwebremoting.extend.DownloadManager.FileGenerator) */ public String addFileTransfer(FileTransfer transfer) throws IOException { OutputStreamLoader loader = null; ByteArrayOutputStream out = null; try { out = new ByteArrayOutputStream(); String mimeType = transfer.getMimeType(); loader = transfer.getOutputStreamLoader(); loader.load(out); String base64data = new String(Base64.encodeBase64(out.toByteArray())); return "'data:" + mimeType + ";base64," + base64data + "'"; } finally { LocalUtil.close(loader); LocalUtil.close(out); } } /* (non-Javadoc) * @see org.directwebremoting.extend.DownloadManager#getFile(java.lang.String) */ public FileTransfer getFileTransfer(String id) { throw new UnsupportedOperationException("data: URLs should not be touched with http:"); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy