Posted: Sun Mar 23, 2003 8:36 pm Post subject: Splitting the File in Client
Master
Joined: 27 Mar 2002 Posts: 207 Location: India
Hi,
I want to split my files in 32kb (32000 bytes) Iam using the java API (client application) to split the file to 32kb irrespective of its size
Since my receiving application can only handles the message of 32kb
I am unable to do the complete splits :
Here with Iam sending the code which splits the file but dosenot split it fully
Please let me know am I using wrong API or methods or wrong procedures please see the usage below.
*******************************
import java.io.*;
public class FileSegment { //start of class
static byte[] b = new byte[900000];
public static void main(String args[]){ // start of psvm
//protected int position=0;
long filenamelength;
int MAX_REC_SIZE = 31977;
int offset=0;
int i=0;
char[] recform = new char[1];
recform[0]='F';
//=new byte[];//=900MB 900000000
FileSegment fs = new FileSegment();
File f =new File("MHQQuery1.txt");
filenamelength=f.length();
System.out.println("The Length of the file"+filenamelength);
if(filenamelength<MAX_REC_SIZE){ // start of if
System.out.println("Add priority 9 and quit");
System.out.println("Put To Local Queue After Adding header");
System.out.println("The Length of the file==>"+filenamelength);
System.exit(1);
} //end of if
else{ //start of else
try { // start of try
// FileInputStream fi = new FileInputStream(f);
java.io.BufferedInputStream bi = new java.io.BufferedInputStream(new java.io.FileInputStream(f));
System.out.println("Can read/not"+f.canRead());
System.out.println("The Mark supported =="+bi.markSupported());
//int g=0;
// for(offset=0;int filenamelength<=f.length();int incr=g+MAX_REC_SIZE)
do{ //do start
i = bi.read(b,offset,MAX_REC_SIZE);
System.out.println("bytes read are"+b);
System.out.println("Put into Q After adding header");
int skip =(int)bi.skip(MAX_REC_SIZE);
System.out.println("skipped bytes is"+skip);
offset=offset+ skip;
System.out.println("Offset is"+offset);
bi.mark(skip);
//bi.pos=skip;
//int remaining=bi.available();
//System.out.println("bytes remaning after Skip is"+remaining);
if(i < MAX_REC_SIZE)
MAX_REC_SIZE=i;
bi.reset();
// position=bi.pos;
// System.out.println("The postion in buffer"+position);
}while(i==-1/*available*/);// do end
System.out.println("reading over");
bi.close();
// f.deleteOnExit();// Will delete the file from current directory when
//reading is over pl take backups before reading
} //end of try
catch(FileNotFoundException fe)
{System.out.println("File not found please give valid file name: "+"The
Cause ==>"+fe.getCause()+fe.getStackTrace());}
catch(IOException io)
{System.out.println("IOException"+io.getCause()+io.getStackTrace()); }
} //end of else
} //end of psvm
}//end of class
You can see lots of unused variables or methods but that is only for future use
Please let me know where am I wrong
Usage is
javac FileSegment.java
java FileSegment (the following output for this)
The Length of the file43660
Can read/not true
The Mark supported ==>true
bytes read are[B@f4a24a
Put into Q After adding header
skipped bytes is31977
Offset is31977
reading over
The MAX_REC_SIZE takes care of the 32kb and some of the System.out.print which given for convineance
Which just says that putting into the local Queue after adding header (the method is to be replaced with this System.out.print )
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum