The LCFrame.java file converts the encoded image of the document sent using the Fax application into frames.
Listing 6-9 shows the LCFrame.java file:
Listing 6-9: The LCFrame.java File
public class LCFrame { byte bytes[]; int bytesCount; public LCFrame(byte b[], int len) { bytes = new byte[256]; bytesCount = 0; bytes = b; bytesCount = len; } public LCFrame() { bytes = new byte[256]; bytesCount = 0; bytes[0] = -1; bytesCount++; bytes[1] = 3; bytesCount++; bytes[2] = 0; bytesCount++; } public void addByte(byte b) { bytes[bytesCount++] = b; } public void setLast(boolean l) { if(l) bytes[1] = 19; else bytes[1] = 3; } public int getFrameType() { if(bytesCount > 2) { int b = bytes[2]; if(b < 0) b = 256 + b; return b; } else { return 0; } } public void setFrameType(byte t) { if(bytesCount > 2) bytes[2] = t; } public boolean isLast() { if(bytesCount > 1) return bytes[1] == 19; else return false; } public byte[] getData() { if(bytesCount <= 5) return null; byte r[] = new byte[bytesCount - 5]; for(int h = 0; h < r.length; h++) r[h] = bytes[h + 3]; return r; } public byte[] getRawData() { byte r[] = new byte[bytesCount]; for(int h = 0; h < r.length; h++) r[h] = bytes[h]; return r; } }
Download this listing.
In the above listing, the LCFrame class converts a fax image to frames. The various methods defined in the LCFrame.java file are:
addByte(): Adds a byte to the fax document.
getFrameType(): Determines the type of frame that the Fax application sends.
setFrameType(): Sets the frame type for the image that the Fax application sends.
isLast():Determines whether the current data byte is the last byte or not.
getData():Retrieves the data that is converted into frames using the LCFrame class.
getRawData():Retrieves the data that the Fax application sends in the form of frames.