Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created March 9, 2017 20:45
Show Gist options
  • Save ssaurel/13b6dbfed6e8b01e152a903493218c8d to your computer and use it in GitHub Desktop.
Save ssaurel/13b6dbfed6e8b01e152a903493218c8d to your computer and use it in GitHub Desktop.
ByteArrayDataSource for the Java Mail API on Android Tutorial
public class ByteArrayDataSource implements DataSource {
private byte[] data;
private String type;
public ByteArrayDataSource(byte[] data, String type) {
super();
this.data = data;
this.type = type;
}
public ByteArrayDataSource(byte[] data) {
super();
this.data = data;
}
public void setType(String type) {
this.type = type;
}
public String getContentType() {
if (type == null)
return "application/octet-stream";
else
return type;
}
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(data);
}
public String getName() {
return "ByteArrayDataSource";
}
public OutputStream getOutputStream() throws IOException {
throw new IOException("Not Supported");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment