大きなpdfファイル(10メガビット)を別のコンピューターに送信する必要があるプロジェクトに取り組んでいますが、最初にパケットに収まるように32000ビットの小さなバイト配列に分割する必要があります。次に、他のコンピューターが必要になりますファイルを作り直すために.私はすでにそれを壊すことができましたが、私はそれを再作成するのに苦労しています.
それが私が今までやってきたことです:
class Example {
public static byte [] buffer = new byte [8];
public static byte [] ArrayCheck = { 0,0,0,0,0,0,0,0};
public static int count =0;
public static void main (String [] args) throws Exception{
int n = 32000;
int temp = 4000;
int counter =0;
byte [] chunk = new byte [n] ;
System.out.println("it worked" +chunk.length);
RandomAccessFile f = new RandomAccessFile("SimpleExample.pdf", "r");
byte[] b = new byte[(int)f.length()];
f.read(b);
System.out.println("it worked" +b.length);
for (int pos = 0; pos < b.length; pos+=n ) {
if ((pos+n)>b.length){
temp =(((pos+n)-b.length)/8+((pos+n)-b.length)%8);
System.arraycopy(b, pos, chunk , 0, temp); // this is the last packets
CreateFile(chunk);
}else {
System.arraycopy(b, pos, chunk , 0, temp);
CreateFile(chunk);
}
counter ++;
}
System.out.println(counter);
}
public static void CreateFile (byte [] data ) throws Exception{
FileOutputStream sigfil = new FileOutputStream("example.pdf", true);
System.arraycopy(data, 3998, buffer , 0, 1);
sigfil.write(data);
if (Arrays.equals(buffer,ArrayCheck)) {
sigfil.close();
count++;
System.out.println(count);
}
}
}
それ、どうやったら出来るの?