Solved

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

Posted on 2008-10-03
2
539 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

740 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