LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-24-2004, 05:46 AM   #1
djadhav
LQ Newbie
 
Registered: Mar 2004
Location: IITKanpur,India
Posts: 24

Rep: Reputation: 15
[java]removing unwanted data from a file


hi,
i have made a program that downloads a file from an Internet sites in 2 chunks. I am sending request for first half of the total byte size of the file and then reading the Input Stream of the server socket byte by byte into a file.Same thing I do for the second chunk of bytes( I append to the same file). Now with each response from the server, a header comes with the byte chunk....................so in the file those headers are also written(two times, one for each request). E.g when i downloaded a .java file, I got the final file as



HTTP/1.0 206 Partial Content
Date: Sat, 23 Oct 2004 18:39:44 GMT
Server: Apache/2.0.49 (Fedora)
Last-Modified: Tue, 10 Sep 2002 09:55:10 GMT
Accept-Ranges: bytes
Content-Type: text/plain; charset=ISO-8859-1
Content-Range: bytes 0-864/1728
Content-Length: 865
Age: 51344
X-Cache: HIT from ernetproxy
Proxy-Connection: close


/**
* this prog. generates various features of cows.
*
* saurabh gupta
* 6th august 2k2
*/
public class cow
{
public static void main(String args[])
{walking_cow();
running_cow();
braking_cow();
apanight_cow();
}
public static void walking_cow()
{
System.out.println("* (__)");
System.out.println(" \\ (oo)");
System.out.println(" \\-------\\/");
System.out.println(" /| |\\");
System.out.println("//||------||\\\\");
System.out.println("\" \"\" \"\" \"");
System.out.println("cow walking");
System.out.println(" ");
}
public static void running_cow()
{
System.out.println(" (__)");
System.out.println(" (oo)");
System.out.println(" /-------\\/");
System.out.println(" / \\ /");
System.out.println("* \\\\--//");
Syste˙HTTP/1.0 206 Partial Content
Date: Sat, 23 Oct 2004 18:39:44 GMT
Server: Apache/2.0.49 (Fedora)
Last-Modified: Tue, 10 Sep 2002 09:55:10 GMT
Accept-Ranges: bytes
Content-Type: text/plain; charset=ISO-8859-1
Content-Range: bytes 865-1727/1728
Content-Length: 863
Age: 51347
X-Cache: HIT from ernetproxy
Proxy-Connection: close

m.out.println(" \" \"");
System.out.println(" cow running");
System.out.println(" ");
}
public static void braking_cow()
{
System.out.println(" (__)");
System.out.println(" (oo)");
System.out.println(" /----------\\/");
System.out.println(" / \\ \\");
System.out.println("* \\\\--------\\\\");
System.out.println(" \" \"");
System.out.println(" cow braking");
System.out.println(" ");
}
public static void apanight_cow()
{
System.out.println(" (__)");
System.out.println(" (--)");
System.out.println(" /----------\\/");
System.out.println(" /| ||");
System.out.println("* ||---------||");
System.out.println(" \"\" \"\"");
System.out.println("cow after pulling a night out");
}
}




You can see two headers, one at the start and one in between. Now how do i remove these headers from the file, or how do i check the header content to get written to the file when i am reading from the input stream of the socket.

please help....its urgent.........

-DJ
 
Old 10-24-2004, 08:32 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,491

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Just retrieve the document size and partial size from the HTTP headers, and copy only the document part to the output file.
The header is separated from the rest by two consecutive CR-LF, so it's easy to detect the header end.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
removing unwanted apps epona Linux - Newbie 1 01-23-2005 03:08 PM
Removing Unwanted Sound Driver toadatrix Suse/Novell 0 10-15-2004 07:51 AM
Removing unwanted desktop /mnt/hd's spalmere Linux - Newbie 3 09-15-2004 11:34 PM
Removing unwanted processes in Slackware Streams Slackware 2 09-13-2003 10:59 PM
Removing unwanted RH 7.2 packages!! CyberDrake Linux - Distributions 1 02-08-2002 05:33 AM


All times are GMT -5. The time now is 08:52 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration