istack-commons.src.main.java.com.sun.istack.ByteArrayDataSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache Show documentation
Show all versions of ehcache Show documentation
Ehcache is an open source, standards-based cache used to boost performance,
offload the database and simplify scalability. Ehcache is robust, proven and full-featured and
this has made it the most widely-used Java-based cache.
package com.sun.istack;
import javax.activation.DataSource;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.OutputStream;
/**
* {@link DataSource} backed by a byte buffer.
*
* @author Kohsuke Kawaguchi
*/
public final class ByteArrayDataSource implements DataSource {
private final String contentType;
private final byte[] buf;
private final int len;
public ByteArrayDataSource(byte[] buf, String contentType) {
this(buf,buf.length,contentType);
}
public ByteArrayDataSource(byte[] buf, int length, String contentType) {
this.buf = buf;
this.len = length;
this.contentType = contentType;
}
public String getContentType() {
if(contentType==null)
return "application/octet-stream";
return contentType;
}
public InputStream getInputStream() {
return new ByteArrayInputStream(buf,0,len);
}
public String getName() {
return null;
}
public OutputStream getOutputStream() {
throw new UnsupportedOperationException();
}
}