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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:41:13+00:00 2026-05-18T00:41:13+00:00

I wan’t to post a CSV file to a web service using the Jersey

  • 0

I wan’t to post a CSV file to a web service using the Jersey Client without having to buffer the csv content in memory.

So I started of with some code similar to this:

String csvContent = [the buffered CSV content];
Client c = Client.create();
WebResource r = c.resouce("http://example.com/services/service");
r.type("text/csv").post(csvContent);

I would like to avoid buffering the entire CSV content in memory before sending to the server, I am aware that I can send a File object using the client and jersey will deal with loading and sending the file, however in this case the CSV content will be generated automatically so what I would really like to do is just simply write it to an OutputStream which goes directly to the server rather than into memory… is there a way I can do this using the Jersey client?

  • 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-05-18T00:41:14+00:00Added an answer on May 18, 2026 at 12:41 am

    It seems Jersey doesn’t support writing direct to the OutputStream however after much digging and merging of a few different thinks I learned along the way I managed to come up with this class.

    Jersey supports passing an InputStream into the post method on WebResource which is read and the content written to the request body.

    I am producing a CSV file from a ResultSet so I wrote a class that extends InputStream and when read() is called it gets a record from the ResultSet and builds a line of the CSV file and returns just one character from the line. Each time read() is called the next character is returned until the whole line is returned at which point the next record is read from the database and the process repeated until there are no records left.

    I am using a library called OpenCSV to build the lines of the CSV file

    public class ResultSetCsvInputStream extends InputStream {
    
     private ResultSet rs;
     private int columns;
    
     private int ch;
     private byte[] line;
    
     /**
      * Construct a new SchemaInputStream
      * @param rs
      * @throws SQLException 
      */
     public ResultSetCsvInputStream(ResultSet rs) throws SQLException {
    
      this.rs = rs;
    
      // write column names
      ResultSetMetaData meta = rs.getMetaData();
      columns = meta.getColumnCount();
      String[] colNames = new String[columns];
      for(int i = 0; i < colNames.length; i++) {
       colNames[i] = meta.getColumnName(i+1);
      }
      writeLine(colNames);
    
     }
    
     private void writeLine(String[] ln) {
      StringWriter strWriter = new StringWriter();
      CSVWriter csv = new CSVWriter(strWriter);
      csv.writeNext(ln);
      line = strWriter.toString().getBytes(Charset.forName("UTF8"));
      ch = 0;
     }
    
     @Override
     public int read() throws IOException {
    
      if(rs == null)
       return -1;
    
      // read the next line
      if(line == null || ch >= line.length) {
    
       // query next line
       try {
        if(rs.next()) {
         String[] record = new String[columns];
         for(int i = 0; i < record.length; i++) {
          record[i] = rs.getString(i+1);
         }
         writeLine(record);
        }
        else {
         rs = null;
         return -1;
        }
       } catch (SQLException e) {
        throw new IOException(e);
       }
    
      }
    
      // read next character
      return line[ch++] & 0xFF;
    
     }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wan't to open a pdf file on Xcode using phone gap[corodova 1.7.0]. Is
I wan't to load some data from my XML file using this function: public
I wan't to consume a web service inside a WPF app. I can add
I wan to get the content within the < p > tag using jQuery.
I wan to monitor changes in android system file /sys/class/net/eth0/operstate for monitoring ethernet state.
i wan to disable drag event using jquery and want to bind one another
I wan to get the value of only one week. I am using the
I wan't to manage the different timezones of my users in my web application,
I wan't to search a filename for example like this string: $filetype = file.php.jpg;
I'm having some paging issues when I wan't to display the next page with

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.