Search in sources :

Example 91 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project vboard by voyages-sncf-technologies.

the class UploadsManager method getImage.

/**
 * Get the base64 encoded image of a pin (entry parameter: id)
 *
 * @return String base64 encoded image
 */
public String getImage(String name) {
    try {
        BufferedImage img = ImageIO.read(getPinsImagesDirectory().resolve(name + ".png").toFile());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ImageIO.write(img, "png", bos);
        byte[] imageBytes = bos.toByteArray();
        bos.close();
        return Base64.getEncoder().encodeToString(imageBytes);
    } catch (IOException e) {
        throw new VBoardException("Image encoding error", e);
    }
}
Also used : VBoardException(com.vsct.vboard.models.VBoardException) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage)

Example 92 with ByteArrayOutputStream

use of org.apache.commons.io.output.ByteArrayOutputStream in project mica2 by obiba.

the class DataAccessRequestsResource method exportCsv.

@GET
@Timed
@Path("/csv")
@Produces("text/csv")
public Response exportCsv(@QueryParam("lang") String lang) {
    List<DataAccessRequest> dataAccessRequests = listByStatusFilteringPermitted(null);
    DataAccessForm dataAccessForm = dataAccessFormService.find().get();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    new CsvReportGenerator(dataAccessRequests, dataAccessForm.getCsvExportFormat(), lang).write(byteArrayOutputStream);
    String date = new DateTime().toString("YYYY-MM-dd");
    return Response.ok(byteArrayOutputStream.toByteArray()).header("Content-Disposition", String.format("attachment; filename=\"Access-Requests-Report_%s.csv\"", date)).build();
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm) DateTime(org.joda.time.DateTime) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)92 Test (org.junit.Test)36 DataOutputStream (java.io.DataOutputStream)15 IOException (java.io.IOException)14 HashSet (java.util.HashSet)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ArrayList (java.util.ArrayList)12 Configuration (org.apache.hadoop.conf.Configuration)12 PrintStream (java.io.PrintStream)10 SparkConf (org.apache.spark.SparkConf)10 Edge (uk.gov.gchq.gaffer.data.element.Edge)10 Element (uk.gov.gchq.gaffer.data.element.Element)10 Entity (uk.gov.gchq.gaffer.data.element.Entity)10 Graph (uk.gov.gchq.gaffer.graph.Graph)10 User (uk.gov.gchq.gaffer.user.User)10 File (java.io.File)9 HashMap (java.util.HashMap)8 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)6 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)6