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 8303579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:34:55+00:00 2026-06-08T17:34:55+00:00

this is my first question in the forum, I hope you can help me

  • 0

this is my first question in the forum, I hope you can help me with this.
My escenary:

  1. A file on the basis that I want to download from a browser
  2. I’m using primefaces, FileDownload and StreamedContent

The problem

The problem is that downloading a file 0Bytes

My view.xhtml:

<p:commandButton id="downloadLink" value="Descargar" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"   
                                         rendered="#{not anexoController.ingresaDatos}" icon="ui-icon-arrowthichk-s">  
                            <p:fileDownload value="#{anexoController.file}" />  
                        </p:commandButton>

My DownloadManger

    public StreamedContent getFile() {
    file = null;
    byte[] bytes = anexoActual.getArchivo(); //anexoActual.getArchivo.length = 53508
    String nombre = anexoActual.getNombre(); 
    String formato = anexoActual.getFormato();
    InputStream stream = new ByteArrayInputStream(bytes);
    try {
        stream.read(bytes);
    } catch (IOException ex) {
        Logger.getLogger(AnexoController.class.getName()).log(Level.SEVERE, null, ex);
    }
    file = new DefaultStreamedContent(stream, formato, nombre);
    return file; //file.steam.buf.length = 53508
}

As you can see the file reaches the file with a length of 53508 bytes, but when the download is complete the only thing that I have the file name and data type

  • 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-08T17:34:56+00:00Added an answer on June 8, 2026 at 5:34 pm

    Look at this code:

    try {
        stream.read(bytes);
    } catch (IOException ex) {
        Logger.getLogger(...)
    }
    

    You’re reading from the stream – back into the byte array which contains the data to start with. Why are you doing that? It’s positioning the stream at the end.

    Just remove that block and it may well be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first question in this forum, so i hope to be clear:
This is my first question on Stack Overflow, so I hope that I'm clear
This is my first question on this forum and I hope u don't blame
This is my first question to this forum. I am trying to make this
(Since this is my first SO question, let me just say I hope it's
It is the first time I ask a question on this forum. Sorry if
I have a problem that I hope you can help/guide me. I saw a
This is my first question here, but I hope I will get a lot
First of all; I'm aware that this question is strange and I will probably
I am new the forum so hope this question is not too elementary or

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.