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

com.nortal.jroad.jaxb.ByteArrayDataSource Maven / Gradle / Ivy

package com.nortal.jroad.jaxb;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.activation.DataSource;

/**
 * A {@link DataSource} implementation, that wraps a byte array. The idea is borrowed from Spring-WS.
 * 
 * @author Dmitri Danilkin
 */
public class ByteArrayDataSource implements DataSource {
  private byte[] data;
  private String contentType;

  public ByteArrayDataSource(String contentType, byte[] data) {
    this.contentType = contentType;
    this.data = data;
  }

  public InputStream getInputStream() throws IOException {
    return new ByteArrayInputStream(data);
  }

  public OutputStream getOutputStream() throws IOException {
    throw new UnsupportedOperationException();
  }

  public String getContentType() {
    return contentType;
  }

  public String getName() {
    return "ByteArrayDataSource";
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy