Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to create a file in java by appending file chunks together

Posted on 2008-10-03
2
Medium Priority
?
555 Views
Last Modified: 2012-06-21
Hi I have a SOAP Message which returns the following schema (parts are starred out for security purposes) :

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <DownloadZipChunkResponse xmlns="http://***.***.gov.uk/***">
      <DownloadZipChunkResult>base64binary</DownloadZipChunkResult>
    </DownloadZipChunkResponse>
  </soap12:Body>
</soap12:Envelope>

The 'base64binary' part of that is a chunk of a file.  The way my program works is that I query the web service with a soap message, sending it the chunk size and the offset so that it know what chunk and size of chunk to send back.

Once I parse the chunk out of the response, I am not sure how I append all of these chunks together to make the overall file.  No idea if I should be using FileStream or any sort of stream or how to write to a location on my machine.

Any help would be much appreciated
0
Comment
Question by:moorcroftlad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 2000 total points
ID: 22635057
Assuming your program is authorized to write a file onto your machine (which it will be if it is an application; if it is an applet it will need additional authority), you can do it with a file stream.

FileOutputStream fo=new FileOutputStream(filename);
fo.write(b);
...
...
//and, eventually
fo.close();


where filename is a String that is a path to a file and b is a array of bytes. There are other possibilities for which you can see the documentation. Most of those calls need to be covered by a try/catch for IOExceptions as well.

If you have any questions, please ask.
0
 

Author Comment

by:moorcroftlad
ID: 22648070
Cheers thats what I needed to know
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question