Solved

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

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
HashMap Vs TreeMap 12 49
Copy Files - Python 7 56
java  and programming certification ? 4 65
Java Jpanels and Jframe 8 20
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now