M
Mark Bratcher
I have a java client program that opens a socket to a web site (port 80)
and reads binary files from the site. Most of the time this works fine.
However, in some cases, I don't get the first 2K bytes (exactly that mount)
of the file. Even though the file is in the same directory structure as
the rest of the files. I can download the file fine using any browser's
file download capability. But my Java program won't see the first 2K bytes.
It works on most other files, just not on a few.
The test program I wrote looks like this:
mport java.net.*;
import java.io.*;
import java.util.*;
public class DumpData extends Object
{
public DumpData( String site, String filePath ) throws IOException
{
Socket sockSite;
try
{
sockSite = new Socket( site, 80 );
}
catch ( IOException e )
{
if ( e.getMessage() == null )
System.out.println("Unable to open " + site );
else
System.out.println("Unable to open " + site + ": " + e.getMessage());
return;
}
BufferedReader in = new BufferedReader( new InputStreamReader(sockSite.getInputStream()) );
BufferedWriter out = new BufferedWriter( new OutputStreamWriter(sockSite.getOutputStream()) );
out.write( "GET " + filePath + "\n\n" );
out.flush();
int c;
int count = 0;
while ( (c = in.read()) >= 0 )
{
count = count + 1;
System.out.print( Integer.toHexString(c) + " " );
if ( (count & 0xF) == 0 )
{
System.out.println( "" );
count = 0;
}
}
in.close();
out.close();
}
}
Any thoughts on this?
Thanks.
Mark
and reads binary files from the site. Most of the time this works fine.
However, in some cases, I don't get the first 2K bytes (exactly that mount)
of the file. Even though the file is in the same directory structure as
the rest of the files. I can download the file fine using any browser's
file download capability. But my Java program won't see the first 2K bytes.
It works on most other files, just not on a few.
The test program I wrote looks like this:
mport java.net.*;
import java.io.*;
import java.util.*;
public class DumpData extends Object
{
public DumpData( String site, String filePath ) throws IOException
{
Socket sockSite;
try
{
sockSite = new Socket( site, 80 );
}
catch ( IOException e )
{
if ( e.getMessage() == null )
System.out.println("Unable to open " + site );
else
System.out.println("Unable to open " + site + ": " + e.getMessage());
return;
}
BufferedReader in = new BufferedReader( new InputStreamReader(sockSite.getInputStream()) );
BufferedWriter out = new BufferedWriter( new OutputStreamWriter(sockSite.getOutputStream()) );
out.write( "GET " + filePath + "\n\n" );
out.flush();
int c;
int count = 0;
while ( (c = in.read()) >= 0 )
{
count = count + 1;
System.out.print( Integer.toHexString(c) + " " );
if ( (count & 0xF) == 0 )
{
System.out.println( "" );
count = 0;
}
}
in.close();
out.close();
}
}
Any thoughts on this?
Thanks.
Mark