-
Notifications
You must be signed in to change notification settings - Fork 0
/
Packetizer.java
80 lines (65 loc) · 2.34 KB
/
Packetizer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Copyright (C) 2010 WeaveBytes, Inc.,
*
* Confidential, all rights reserved. No distribution is permitted.
___ ______ ____ ________
\ \ __ / __| / \ / ___|
\ \ / \ / |_ / /\ \ / |_
\ \/ \/ /| _| / /__\ \/ /| _|
\ /\ / | |__/ ______ / | |___
\__/ \__/ |_______/ \ _/ |______|
___ __
______ | | ________ __ __ | |
/ ___| | | / __ \ | | | | _______| |
| | | | | | | | | | | | / ____| |
| |____| |__ | |__| |__| \____/ | \ \____| |
\_______|______\________/__ \________/__ \_________|
Description : Packetizer.java is the class for containing information about packets
Creation Date : August 04, 2011
Authors : Simranpal Singh, Varinder Pal Singh
Project Manager : Navjot Singh
*/
import java.io.*;
class Packetizer {
private InputStream is;
private int size;
private OutputStream f;
private int pktCount = -1;
private int curPkt = 0;
Packetizer(String filename) throws Exception {
is = new FileInputStream(filename);
size = is.available();
pktCount = size/Config.FTP_PKT_SIZE;
if(size%Config.FTP_PKT_SIZE != 0) pktCount ++;
log.info("Created Packetizer for " + filename + ", size=" + size + ", pktCount=" + pktCount);
}
public int count() { return pktCount; }
public String nextPacket() throws Exception {
String packet="";
byte data[] = new byte[Config.FTP_PKT_SIZE];
int len = is.read(data);
log.debug("len = " + len);
curPkt++;
return new String(data, 0, len);
}
public boolean hasMorePackets() { return curPkt < pktCount;}
public void release() throws Exception{
is.close();
}
public static void main(String args[]) {
try
{
int pktCount = 1;
Packetizer pizer = new Packetizer(args[0]);
while(pizer.hasMorePackets()) {
System.out.println(pktCount + ":" + pizer.nextPacket());
pktCount++;
}
pizer.release();
}
catch(Exception e)
{
System.out.println(e);
}
}
}