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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:24:56+00:00 2026-06-14T14:24:56+00:00

I have what I expect would be a pretty common task, but I can’t

  • 0

I have what I expect would be a pretty common task, but I can’t find any straight-forward answers anywhere, so any help here would be greatly appreciated.

Short version:
How can I make an IResourceStream from an SmbFile’s inputStream?

Long version:
In my Wicket app, I have users fill out a questionnaire and then download a file once they’ve completed it properly. The file is on a Samba server, so I’m using SmbFile, which is working perfectly, so no issue with that. I’m using the AJAXDownload that was written by Sven Meier, Ernesto Barreiro, and Jordi Deu-Pons because I need my button to have Ajax functionality to check that the form was filled out properly, and then start the download. When I was starting out with the file on my computer, I could simply use

final AJAXDownload download = new AJAXDownload()
        {
            @Override
            protected IResourceStream getResourceStream()
            {                   
                IResourceStream resStream = new FileResourceStream(file);

                return resStream;
            }
            @Override
            protected String getFileName() {
                return fileName;
            }
        };
        form.add(download);

But now that I’m using SmbFile through JCIFS, I can’t just make a new FileResourceStream. I found that I can use java.io.File.createTempFile to make a tempfile from the smbFile’s inputStream, and then use the temp file like this:

protected IResourceStream getResourceStream()
            {                   
                java.io.File tempFile = null;
                try {
                    tempFile = File.createTempFile(smbFile.getName(), smbFile.getContentType());
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                try {
                    Files.writeTo(tempFile, smbFile.getInputStream());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                IResourceStream resStream = new FileResourceStream(tempFile);
                return resStream;
            }

And this works fine for small files, but I will also have some rather large files and since it makes a temp copy of the file before sending it down, it takes a very long time and is just poor design.
Any ideas of how I can get my smbFile downloaded in the wicket app?

Edit:
Thanks to Joop Eggen, and the book ‘Enjoying Web Development with Wicket’ by Kent Ka lok Tong, I have the solution below in case anyone else ends up in a similar situation:

final AJAXDownload download = new AJAXDownload()
        {
            @Override
            protected IResourceStream getResourceStream()
            {                   
                IResourceStream resStream = new AbstractResourceStream() {
                    InputStream inStream;
                    public InputStream getInputStream() throws ResourceStreamNotFoundException{
                        try {
                            inStream = smbFile.getInputStream();
                        } catch (IOException e) {                               
                            e.printStackTrace();
                        }
                        return inStream;
                    }
                    public void close() throws IOException {
                        inStream.close();
                    }
                    public String getContentType() {
                        return smbFile.getContentType();
                    }
                };
                return resStream;
            }
            @Override
            protected String getFileName() {
                return smbFileName;
            }
        };
        form.add(download);
  • 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-14T14:24:57+00:00Added an answer on June 14, 2026 at 2:24 pm

    You should derive a SmbResourceStream that extends AbstractResourceStream, and implement providing an InputStream for reading by overriding getInputStream and close. You already have smbFile.getInputStream().

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

Sidebar

Related Questions

I would expect something like this to be pretty popular in demand but I
I have what seems to be a pretty common CSS inheritance situation, but I
I have the following code (ObjA) and it works as I would expect, instance
I have a number of pages in my site, as one would expect. For
I have the following code, which works as I expect. What I would like
I have been playing with Expect/TCL today and I was hoping someone can tell
I am prob. being pretty dense here but I can't figure out exactly what
I have a pretty decent background in Java and C++, but I'm struggling to
I have a question about the following code in TCL/EXPECT: expect { timeout {
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);

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.