Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:01:06+00:00 2026-06-01T20:01:06+00:00

My requirement is, I should send a 10MB zip file to the client with

  • 0

My requirement is, I should send a 10MB zip file to the client with a restful service. I found the code in forums that sending a StreamingOutput object is the better way, but how can I create a StreamingOutput object in the following code:

@Path("PDF-file.pdf/")
@GET
@Produces({"application/pdf"})
public StreamingOutput getPDF() throws Exception {
  return new StreamingOutput() {
     public void write(OutputStream output) throws IOException, WebApplicationException      
     {
        try {
            //------
        } catch (Exception e) {
            throw new WebApplicationException(e);
        }
     }
  };
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:01:07+00:00Added an answer on June 1, 2026 at 8:01 pm

    Its the better way and easy way for file dowload.

    private static final String FILE_PATH = "d:\\Test2.zip";
    @GET
    @Path("/get")
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    public Response getFile() {
        File file = new File(FILE_PATH);
        ResponseBuilder response = Response.ok((Object) file);
        response.header("Content-Disposition", "attachment; filename=newfile.zip");
        return response.build();
    
    }
    

    For your code as you asked:

    @GET
    @Path("/helloWorldZip") 
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    public StreamingOutput helloWorldZip() throws Exception {
        return new StreamingOutput(){
        @Override
            public void write(OutputStream arg0) throws IOException, WebApplicationException {
                // TODO Auto-generated method stub
                BufferedOutputStream bus = new BufferedOutputStream(arg0);
                try {
                    //ByteArrayInputStream reader = (ByteArrayInputStream) Thread.currentThread().getContextClassLoader().getResourceAsStream();     
                    //byte[] input = new byte[2048];  
                    java.net.URL uri = Thread.currentThread().getContextClassLoader().getResource("");
                    File file = new File("D:\\Test1.zip");
                    FileInputStream fizip = new FileInputStream(file);
                    byte[] buffer2 = IOUtils.toByteArray(fizip);
                    bus.write(buffer2);
                } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                }
            }
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Requirement is whenever I click on the Extension Icon that should send a
Requirement : Should update MySQL database with that of MS Sql Server updates which
I have a requirement that a SPList should be sorted by the Priority field
My requirement is that given a string as key to the map, I should
The requirement of the TCP server: receive from each client and send result back
I have a requirement to parse a huge text file and send parts of
I have a UIScrollView with the requirement that, when zooming, the contentSize.height should remain
I have the requirement that whenever there is a model get's added/changed/deleted, it should
I am making an iPhone app, where the requirement is such that user should
can you just tell me for which type of requirement we should choose framework

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.