protected void initialize() { add((dataLink = new ResourceLink<byte[]>("data", new AbstractResource() { @Override protected ResourceResponse newResourceResponse(Attributes attributes) { ResourceResponse resourceResponse = new ResourceResponse(); resourceResponse.setContentType("application/octet-stream"); String filename = nameModel.getObject(); resourceResponse.setFileName(filename); resourceResponse.setWriteCallback(new WriteCallback() { @Override public void writeData(Attributes attributes) throws IOException { byte[] data = (byte[])BinaryViewPanel.this.getModelObject(); if(data!=null) { OutputStream outputStream = attributes.getResponse().getOutputStream(); outputStream.write((byte[])BinaryViewPanel.this.getModelObject()); } } }); return resourceResponse; } })).setBody(nameModel)); }
/** * Creates a new link to the exported data for the provided {@link IDataExporter}. * * @param componentId * The component of the link. * @param dataExporter * The data exporter to use to export the data. * @return a new link to the exported data for the provided {@link IDataExporter}. */ protected Component createExportLink(String componentId, final IDataExporter dataExporter) { IResource resource = new ResourceStreamResource() { @Override protected IResourceStream getResourceStream(Attributes attributes) { return new DataExportResourceStreamWriter(dataExporter, getTable()); } }.setFileName(fileNameModel.getObject() + "." + dataExporter.getFileNameExtension()); return new ResourceLink<Void>(componentId, resource) .setBody(dataExporter.getDataFormatNameModel()); }