updated build scripts to sbt 1.0
added service returning a tar archive with all the requested packages
This commit is contained in:
@@ -9,7 +9,8 @@ import com.oggio88.jpacrepo.model.PkgName;
|
||||
import com.oggio88.jpacrepo.model.StringList;
|
||||
import com.oggio88.jpacrepo.pacbase.Parser;
|
||||
import com.oggio88.jpacrepo.persistence.QueryEngine;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.ejb.*;
|
||||
@@ -354,9 +355,54 @@ public class PacmanWebService
|
||||
}
|
||||
|
||||
@POST
|
||||
public Response foo()
|
||||
@Path("/downloadTar")
|
||||
@Produces("application/x-tar")
|
||||
public Response downloadTar(List<String> files)
|
||||
{
|
||||
TarArchiveouputStream tais = new TarArchiveOutputStream();
|
||||
for(String fname : files)
|
||||
{
|
||||
if(!ctx.getFile(fname).exists()) throw new NotFoundException(String.format("Package file '%s' does not exist", fname));
|
||||
}
|
||||
StreamingOutput stream = new StreamingOutput()
|
||||
{
|
||||
@Override
|
||||
public void write(OutputStream output) throws IOException, WebApplicationException
|
||||
{
|
||||
TarArchiveOutputStream taos = new TarArchiveOutputStream(output);
|
||||
try
|
||||
{
|
||||
for (String fname : files)
|
||||
{
|
||||
File file = ctx.getFile(fname);
|
||||
FileInputStream input = new FileInputStream(file);
|
||||
|
||||
TarArchiveEntry entry = new TarArchiveEntry(fname);
|
||||
entry.setSize(file.length());
|
||||
taos.putArchiveEntry(entry);
|
||||
byte[] bytes = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
int size = input.read(bytes);
|
||||
if (size < 0) break;
|
||||
else taos.write(bytes, 0, size);
|
||||
}
|
||||
taos.closeArchiveEntry();
|
||||
}
|
||||
taos.close();
|
||||
output.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new WebApplicationException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
taos.close();
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
return Response.ok(stream).build();
|
||||
}
|
||||
|
||||
private Response manageQueryResult(List<PkgData> list)
|
||||
|
Reference in New Issue
Block a user