h u f f m a n algorithm class
Post on 21-Jul-2015
272 Views
Preview:
TRANSCRIPT
Class BitInputStream
javalangObject
javaioInputStream
BitInputStreamAll Implemented Interfaces
javaioCloseablepublic class BitInputStreamextends javaioInputStream
Reads bits-at-a-time where the number of bits is between 1 and 32 Updated for version 20 to extend javaioInputStream This class can be used together with BitOutputStream to facilitate reading and writing data several bits-at-a-time BitInputStream objects that are constructed from a File support reset() However if constructed from an InputStream an object cannot be reset
Any exceptions generated are rethrown as RuntimeException objects so client code does not have to catch or rethrow them (Unless the extension of InputStream requires throwing as another type of exception eg as with method read
Constructor Summary
BitInputStream(javaioFile file) Construct a bit-at-a-time input stream from file
BitInputStream(javaioInputStream in) Open a bit-at-a-time stream that reads from supplied InputStream
BitInputStream(javalangString filename) Construct a bit-at-a-time input stream from a file whose name is supplied
Method Summary
void close() Closes the input stream
boolean markSupported() Return true if the stream has been initialized from a File and is thus reset-able
int read() Required by classes extending InputStream returns the next byte from this stream as an int value
int readBits(int howManyBits) Returns the number of bits requested as rightmost bits in returned value returns -1 if not enough bits available to satisfy the request
void reset() Reset stream to beginning
Methods inherited from class javaioInputStream
available mark read read skip
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
BitInputStream
public BitInputStream(javalangString filename)Construct a bit-at-a-time input stream from a file whose name is supplied Parametersfilename - is the name of the file that will be read Throws javalangRuntimeException - if filename cannot be opened
BitInputStream
public BitInputStream(javaioFile file)Construct a bit-at-a-time input stream from file Parametersfile - is the File that is the source of the input Throws RuntimeExceptoin - if file cannot be opened
BitInputStream
public BitInputStream(javaioInputStream in)Open a bit-at-a-time stream that reads from supplied InputStream If this constructor is used the BitInputStream is not reset-able Parametersin - is the stream from which bits are read
Method Detail
markSupported
public boolean markSupported()Return true if the stream has been initialized from a File and is thus reset-able If constructed from an InputStream it is not reset-able OverridesmarkSupported in class javaioInputStreamReturnstrue if stream can be reset (it has been constructed appropriately from a File)
reset
public void reset() throws javaioIOException
Reset stream to beginning The implementation creates a new stream Overridesreset in class javaioInputStreamThrows javaioIOException - if not reset-able (eg constructed from InputStream)
close
public void close()Closes the input stream Specified byclose in interface javaioCloseableOverridesclose in class javaioInputStreamThrows javalangRuntimeException - if the close fails
readBits
public int readBits(int howManyBits) throws javaioIOException
Returns the number of bits requested as rightmost bits in returned value returns -1 if not enough bits available to satisfy the request ParametershowManyBits - is the number of bits to read and return Returnsthe value read only rightmost howManyBits are valid returns -1 if not enough bits left Throws javaioIOException
read
public int read() throws javaioIOException
Required by classes extending InputStream returns the next byte from this stream as an int value Specified byread in class javaioInputStreamReturnsthe next byte from this stream Throws javaioIOException
Class BitOutputStream
javalangObject
javaioOutputStream
BitOutputStreamAll Implemented Interfaces
javaioCloseable javaioFlushablepublic class BitOutputStreamextends javaioOutputStream
Constructor Summary
BitOutputStream(javaioOutputStream out) Create a stream that writes-through to the OutputStream object passed as a parameter
BitOutputStream(javalangString filename) Construct a bit-at-a-time output stream with specified file name
Method Summary
void close() Releases system resources associated with file and flushes bits not yet written
void flush() Flushes bits not yet written must be called by client programs if close isnt called
void write(int b) Required by OutputStream subclasses write the low 8-bits to the underlying outputstream
void writeBits(int howManyBits int value) Write specified number of bits from value to a file
Methods inherited from class javaioOutputStream
write write
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
BitOutputStream
public BitOutputStream(javaioOutputStream out)Create a stream that writes-through to the OutputStream object passed as a parameter Parametersout - is the output stream to which bits are written
BitOutputStream
public BitOutputStream(javalangString filename)Construct a bit-at-a-time output stream with specified file name Parameters
filename - is the name of the file being written Throws javalangRuntimeException - if opening file fails for either FileNotFound or for Security exceptoins
Method Detail
write
public void write(int b) throws javaioIOException
Required by OutputStream subclasses write the low 8-bits to the underlying outputstream Specified bywrite in class javaioOutputStreamThrows javaioIOException
flush
public void flush()Flushes bits not yet written must be called by client programs if close isnt called Specified byflush in interface javaioFlushableOverridesflush in class javaioOutputStreamThrows javalangRuntimeException - if theres a problem writing bits
close
public void close()Releases system resources associated with file and flushes bits not yet written Either this function or flush must be called or not all bits will be written Specified byclose in interface javaioCloseableOverridesclose in class javaioOutputStreamThrows javalangRuntimeException - if close fails
writeBits
public void writeBits(int howManyBits int value)
Write specified number of bits from value to a file ParametershowManyBits - is number of bits to write (1-32)value - is source of bits rightmost bits are written Throws javalangRuntimeException - if theres an IO problem writing bits
Class Diff
javalangObject
Diffpublic class Diffextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourChooser
Constructor Summary
Diff()
Method Summary
static boolean doDiffer(javaioFile[] files)
static void main(javalangString[] args)
static void showMessage(javalangString message)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
Diff
public Diff()
Method Detail
showMessage
public static void showMessage(javalangString message)
doDiffer
public static boolean doDiffer(javaioFile[] files)
main
public static void main(javalangString[] args)
Class Huff
javalangObject
Huffpublic class Huffextends javalangObject
Mainlaunch program for Huff assignment A better comment than this is warranted
Constructor Summary
Huff()
Method Summary
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
Huff
public Huff()
Method Detail
main
public static void main(javalangString[] args)
Class HuffMark
javalangObject
HuffMarkpublic class HuffMarkextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourOpenChooser
Constructor Summary
HuffMark()
Method Summary
void compress(javaioFile f)
void doMark()
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourOpenChooser
protected static javaxswingJFileChooser ourOpenChooser
Constructor Detail
HuffMark
public HuffMark()
Method Detail
compress
public void compress(javaioFile f) throws javaioIOException
Throws javaioIOException
doMark
public void doMark()
throws javaioIOExceptionThrows javaioIOException
main
public static void main(javalangString[] args) throws javaioIOException
Throws javaioIOException
Class HuffViewer
javalangObject
javaawtComponent
javaawtContainer
javaawtWindow
javaawtFrame
javaxswingJFrame
HuffViewerAll Implemented Interfaces
javaawtimageImageObserver javaawtMenuContainer javaioSerializable javaxaccessibilityAccessible javaxswingRootPaneContainer javaxswingWindowConstants
public class HuffViewerextends javaxswingJFrame
The GUIView for Huffman coding assignment Clients communicate with this view by attaching a model and then using the menu choicesoptions that are part of the GUI Thus client code that fails to call setModel will almost certainly not work and generate null pointer problems because the viewGUI will not have an associated model
See AlsoSerialized Form
Nested Class Summary
Nested classesinterfaces inherited from class javaxswingJFrame
javaxswingJFrameAccessibleJFrame
Nested classesinterfaces inherited from class javaawtFrame
javaawtFrameAccessibleAWTFrame
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
BitInputStream
public BitInputStream(javalangString filename)Construct a bit-at-a-time input stream from a file whose name is supplied Parametersfilename - is the name of the file that will be read Throws javalangRuntimeException - if filename cannot be opened
BitInputStream
public BitInputStream(javaioFile file)Construct a bit-at-a-time input stream from file Parametersfile - is the File that is the source of the input Throws RuntimeExceptoin - if file cannot be opened
BitInputStream
public BitInputStream(javaioInputStream in)Open a bit-at-a-time stream that reads from supplied InputStream If this constructor is used the BitInputStream is not reset-able Parametersin - is the stream from which bits are read
Method Detail
markSupported
public boolean markSupported()Return true if the stream has been initialized from a File and is thus reset-able If constructed from an InputStream it is not reset-able OverridesmarkSupported in class javaioInputStreamReturnstrue if stream can be reset (it has been constructed appropriately from a File)
reset
public void reset() throws javaioIOException
Reset stream to beginning The implementation creates a new stream Overridesreset in class javaioInputStreamThrows javaioIOException - if not reset-able (eg constructed from InputStream)
close
public void close()Closes the input stream Specified byclose in interface javaioCloseableOverridesclose in class javaioInputStreamThrows javalangRuntimeException - if the close fails
readBits
public int readBits(int howManyBits) throws javaioIOException
Returns the number of bits requested as rightmost bits in returned value returns -1 if not enough bits available to satisfy the request ParametershowManyBits - is the number of bits to read and return Returnsthe value read only rightmost howManyBits are valid returns -1 if not enough bits left Throws javaioIOException
read
public int read() throws javaioIOException
Required by classes extending InputStream returns the next byte from this stream as an int value Specified byread in class javaioInputStreamReturnsthe next byte from this stream Throws javaioIOException
Class BitOutputStream
javalangObject
javaioOutputStream
BitOutputStreamAll Implemented Interfaces
javaioCloseable javaioFlushablepublic class BitOutputStreamextends javaioOutputStream
Constructor Summary
BitOutputStream(javaioOutputStream out) Create a stream that writes-through to the OutputStream object passed as a parameter
BitOutputStream(javalangString filename) Construct a bit-at-a-time output stream with specified file name
Method Summary
void close() Releases system resources associated with file and flushes bits not yet written
void flush() Flushes bits not yet written must be called by client programs if close isnt called
void write(int b) Required by OutputStream subclasses write the low 8-bits to the underlying outputstream
void writeBits(int howManyBits int value) Write specified number of bits from value to a file
Methods inherited from class javaioOutputStream
write write
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
BitOutputStream
public BitOutputStream(javaioOutputStream out)Create a stream that writes-through to the OutputStream object passed as a parameter Parametersout - is the output stream to which bits are written
BitOutputStream
public BitOutputStream(javalangString filename)Construct a bit-at-a-time output stream with specified file name Parameters
filename - is the name of the file being written Throws javalangRuntimeException - if opening file fails for either FileNotFound or for Security exceptoins
Method Detail
write
public void write(int b) throws javaioIOException
Required by OutputStream subclasses write the low 8-bits to the underlying outputstream Specified bywrite in class javaioOutputStreamThrows javaioIOException
flush
public void flush()Flushes bits not yet written must be called by client programs if close isnt called Specified byflush in interface javaioFlushableOverridesflush in class javaioOutputStreamThrows javalangRuntimeException - if theres a problem writing bits
close
public void close()Releases system resources associated with file and flushes bits not yet written Either this function or flush must be called or not all bits will be written Specified byclose in interface javaioCloseableOverridesclose in class javaioOutputStreamThrows javalangRuntimeException - if close fails
writeBits
public void writeBits(int howManyBits int value)
Write specified number of bits from value to a file ParametershowManyBits - is number of bits to write (1-32)value - is source of bits rightmost bits are written Throws javalangRuntimeException - if theres an IO problem writing bits
Class Diff
javalangObject
Diffpublic class Diffextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourChooser
Constructor Summary
Diff()
Method Summary
static boolean doDiffer(javaioFile[] files)
static void main(javalangString[] args)
static void showMessage(javalangString message)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
Diff
public Diff()
Method Detail
showMessage
public static void showMessage(javalangString message)
doDiffer
public static boolean doDiffer(javaioFile[] files)
main
public static void main(javalangString[] args)
Class Huff
javalangObject
Huffpublic class Huffextends javalangObject
Mainlaunch program for Huff assignment A better comment than this is warranted
Constructor Summary
Huff()
Method Summary
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
Huff
public Huff()
Method Detail
main
public static void main(javalangString[] args)
Class HuffMark
javalangObject
HuffMarkpublic class HuffMarkextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourOpenChooser
Constructor Summary
HuffMark()
Method Summary
void compress(javaioFile f)
void doMark()
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourOpenChooser
protected static javaxswingJFileChooser ourOpenChooser
Constructor Detail
HuffMark
public HuffMark()
Method Detail
compress
public void compress(javaioFile f) throws javaioIOException
Throws javaioIOException
doMark
public void doMark()
throws javaioIOExceptionThrows javaioIOException
main
public static void main(javalangString[] args) throws javaioIOException
Throws javaioIOException
Class HuffViewer
javalangObject
javaawtComponent
javaawtContainer
javaawtWindow
javaawtFrame
javaxswingJFrame
HuffViewerAll Implemented Interfaces
javaawtimageImageObserver javaawtMenuContainer javaioSerializable javaxaccessibilityAccessible javaxswingRootPaneContainer javaxswingWindowConstants
public class HuffViewerextends javaxswingJFrame
The GUIView for Huffman coding assignment Clients communicate with this view by attaching a model and then using the menu choicesoptions that are part of the GUI Thus client code that fails to call setModel will almost certainly not work and generate null pointer problems because the viewGUI will not have an associated model
See AlsoSerialized Form
Nested Class Summary
Nested classesinterfaces inherited from class javaxswingJFrame
javaxswingJFrameAccessibleJFrame
Nested classesinterfaces inherited from class javaawtFrame
javaawtFrameAccessibleAWTFrame
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
public void reset() throws javaioIOException
Reset stream to beginning The implementation creates a new stream Overridesreset in class javaioInputStreamThrows javaioIOException - if not reset-able (eg constructed from InputStream)
close
public void close()Closes the input stream Specified byclose in interface javaioCloseableOverridesclose in class javaioInputStreamThrows javalangRuntimeException - if the close fails
readBits
public int readBits(int howManyBits) throws javaioIOException
Returns the number of bits requested as rightmost bits in returned value returns -1 if not enough bits available to satisfy the request ParametershowManyBits - is the number of bits to read and return Returnsthe value read only rightmost howManyBits are valid returns -1 if not enough bits left Throws javaioIOException
read
public int read() throws javaioIOException
Required by classes extending InputStream returns the next byte from this stream as an int value Specified byread in class javaioInputStreamReturnsthe next byte from this stream Throws javaioIOException
Class BitOutputStream
javalangObject
javaioOutputStream
BitOutputStreamAll Implemented Interfaces
javaioCloseable javaioFlushablepublic class BitOutputStreamextends javaioOutputStream
Constructor Summary
BitOutputStream(javaioOutputStream out) Create a stream that writes-through to the OutputStream object passed as a parameter
BitOutputStream(javalangString filename) Construct a bit-at-a-time output stream with specified file name
Method Summary
void close() Releases system resources associated with file and flushes bits not yet written
void flush() Flushes bits not yet written must be called by client programs if close isnt called
void write(int b) Required by OutputStream subclasses write the low 8-bits to the underlying outputstream
void writeBits(int howManyBits int value) Write specified number of bits from value to a file
Methods inherited from class javaioOutputStream
write write
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
BitOutputStream
public BitOutputStream(javaioOutputStream out)Create a stream that writes-through to the OutputStream object passed as a parameter Parametersout - is the output stream to which bits are written
BitOutputStream
public BitOutputStream(javalangString filename)Construct a bit-at-a-time output stream with specified file name Parameters
filename - is the name of the file being written Throws javalangRuntimeException - if opening file fails for either FileNotFound or for Security exceptoins
Method Detail
write
public void write(int b) throws javaioIOException
Required by OutputStream subclasses write the low 8-bits to the underlying outputstream Specified bywrite in class javaioOutputStreamThrows javaioIOException
flush
public void flush()Flushes bits not yet written must be called by client programs if close isnt called Specified byflush in interface javaioFlushableOverridesflush in class javaioOutputStreamThrows javalangRuntimeException - if theres a problem writing bits
close
public void close()Releases system resources associated with file and flushes bits not yet written Either this function or flush must be called or not all bits will be written Specified byclose in interface javaioCloseableOverridesclose in class javaioOutputStreamThrows javalangRuntimeException - if close fails
writeBits
public void writeBits(int howManyBits int value)
Write specified number of bits from value to a file ParametershowManyBits - is number of bits to write (1-32)value - is source of bits rightmost bits are written Throws javalangRuntimeException - if theres an IO problem writing bits
Class Diff
javalangObject
Diffpublic class Diffextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourChooser
Constructor Summary
Diff()
Method Summary
static boolean doDiffer(javaioFile[] files)
static void main(javalangString[] args)
static void showMessage(javalangString message)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
Diff
public Diff()
Method Detail
showMessage
public static void showMessage(javalangString message)
doDiffer
public static boolean doDiffer(javaioFile[] files)
main
public static void main(javalangString[] args)
Class Huff
javalangObject
Huffpublic class Huffextends javalangObject
Mainlaunch program for Huff assignment A better comment than this is warranted
Constructor Summary
Huff()
Method Summary
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
Huff
public Huff()
Method Detail
main
public static void main(javalangString[] args)
Class HuffMark
javalangObject
HuffMarkpublic class HuffMarkextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourOpenChooser
Constructor Summary
HuffMark()
Method Summary
void compress(javaioFile f)
void doMark()
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourOpenChooser
protected static javaxswingJFileChooser ourOpenChooser
Constructor Detail
HuffMark
public HuffMark()
Method Detail
compress
public void compress(javaioFile f) throws javaioIOException
Throws javaioIOException
doMark
public void doMark()
throws javaioIOExceptionThrows javaioIOException
main
public static void main(javalangString[] args) throws javaioIOException
Throws javaioIOException
Class HuffViewer
javalangObject
javaawtComponent
javaawtContainer
javaawtWindow
javaawtFrame
javaxswingJFrame
HuffViewerAll Implemented Interfaces
javaawtimageImageObserver javaawtMenuContainer javaioSerializable javaxaccessibilityAccessible javaxswingRootPaneContainer javaxswingWindowConstants
public class HuffViewerextends javaxswingJFrame
The GUIView for Huffman coding assignment Clients communicate with this view by attaching a model and then using the menu choicesoptions that are part of the GUI Thus client code that fails to call setModel will almost certainly not work and generate null pointer problems because the viewGUI will not have an associated model
See AlsoSerialized Form
Nested Class Summary
Nested classesinterfaces inherited from class javaxswingJFrame
javaxswingJFrameAccessibleJFrame
Nested classesinterfaces inherited from class javaawtFrame
javaawtFrameAccessibleAWTFrame
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
javaioOutputStream
BitOutputStreamAll Implemented Interfaces
javaioCloseable javaioFlushablepublic class BitOutputStreamextends javaioOutputStream
Constructor Summary
BitOutputStream(javaioOutputStream out) Create a stream that writes-through to the OutputStream object passed as a parameter
BitOutputStream(javalangString filename) Construct a bit-at-a-time output stream with specified file name
Method Summary
void close() Releases system resources associated with file and flushes bits not yet written
void flush() Flushes bits not yet written must be called by client programs if close isnt called
void write(int b) Required by OutputStream subclasses write the low 8-bits to the underlying outputstream
void writeBits(int howManyBits int value) Write specified number of bits from value to a file
Methods inherited from class javaioOutputStream
write write
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
BitOutputStream
public BitOutputStream(javaioOutputStream out)Create a stream that writes-through to the OutputStream object passed as a parameter Parametersout - is the output stream to which bits are written
BitOutputStream
public BitOutputStream(javalangString filename)Construct a bit-at-a-time output stream with specified file name Parameters
filename - is the name of the file being written Throws javalangRuntimeException - if opening file fails for either FileNotFound or for Security exceptoins
Method Detail
write
public void write(int b) throws javaioIOException
Required by OutputStream subclasses write the low 8-bits to the underlying outputstream Specified bywrite in class javaioOutputStreamThrows javaioIOException
flush
public void flush()Flushes bits not yet written must be called by client programs if close isnt called Specified byflush in interface javaioFlushableOverridesflush in class javaioOutputStreamThrows javalangRuntimeException - if theres a problem writing bits
close
public void close()Releases system resources associated with file and flushes bits not yet written Either this function or flush must be called or not all bits will be written Specified byclose in interface javaioCloseableOverridesclose in class javaioOutputStreamThrows javalangRuntimeException - if close fails
writeBits
public void writeBits(int howManyBits int value)
Write specified number of bits from value to a file ParametershowManyBits - is number of bits to write (1-32)value - is source of bits rightmost bits are written Throws javalangRuntimeException - if theres an IO problem writing bits
Class Diff
javalangObject
Diffpublic class Diffextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourChooser
Constructor Summary
Diff()
Method Summary
static boolean doDiffer(javaioFile[] files)
static void main(javalangString[] args)
static void showMessage(javalangString message)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
Diff
public Diff()
Method Detail
showMessage
public static void showMessage(javalangString message)
doDiffer
public static boolean doDiffer(javaioFile[] files)
main
public static void main(javalangString[] args)
Class Huff
javalangObject
Huffpublic class Huffextends javalangObject
Mainlaunch program for Huff assignment A better comment than this is warranted
Constructor Summary
Huff()
Method Summary
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
Huff
public Huff()
Method Detail
main
public static void main(javalangString[] args)
Class HuffMark
javalangObject
HuffMarkpublic class HuffMarkextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourOpenChooser
Constructor Summary
HuffMark()
Method Summary
void compress(javaioFile f)
void doMark()
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourOpenChooser
protected static javaxswingJFileChooser ourOpenChooser
Constructor Detail
HuffMark
public HuffMark()
Method Detail
compress
public void compress(javaioFile f) throws javaioIOException
Throws javaioIOException
doMark
public void doMark()
throws javaioIOExceptionThrows javaioIOException
main
public static void main(javalangString[] args) throws javaioIOException
Throws javaioIOException
Class HuffViewer
javalangObject
javaawtComponent
javaawtContainer
javaawtWindow
javaawtFrame
javaxswingJFrame
HuffViewerAll Implemented Interfaces
javaawtimageImageObserver javaawtMenuContainer javaioSerializable javaxaccessibilityAccessible javaxswingRootPaneContainer javaxswingWindowConstants
public class HuffViewerextends javaxswingJFrame
The GUIView for Huffman coding assignment Clients communicate with this view by attaching a model and then using the menu choicesoptions that are part of the GUI Thus client code that fails to call setModel will almost certainly not work and generate null pointer problems because the viewGUI will not have an associated model
See AlsoSerialized Form
Nested Class Summary
Nested classesinterfaces inherited from class javaxswingJFrame
javaxswingJFrameAccessibleJFrame
Nested classesinterfaces inherited from class javaawtFrame
javaawtFrameAccessibleAWTFrame
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
filename - is the name of the file being written Throws javalangRuntimeException - if opening file fails for either FileNotFound or for Security exceptoins
Method Detail
write
public void write(int b) throws javaioIOException
Required by OutputStream subclasses write the low 8-bits to the underlying outputstream Specified bywrite in class javaioOutputStreamThrows javaioIOException
flush
public void flush()Flushes bits not yet written must be called by client programs if close isnt called Specified byflush in interface javaioFlushableOverridesflush in class javaioOutputStreamThrows javalangRuntimeException - if theres a problem writing bits
close
public void close()Releases system resources associated with file and flushes bits not yet written Either this function or flush must be called or not all bits will be written Specified byclose in interface javaioCloseableOverridesclose in class javaioOutputStreamThrows javalangRuntimeException - if close fails
writeBits
public void writeBits(int howManyBits int value)
Write specified number of bits from value to a file ParametershowManyBits - is number of bits to write (1-32)value - is source of bits rightmost bits are written Throws javalangRuntimeException - if theres an IO problem writing bits
Class Diff
javalangObject
Diffpublic class Diffextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourChooser
Constructor Summary
Diff()
Method Summary
static boolean doDiffer(javaioFile[] files)
static void main(javalangString[] args)
static void showMessage(javalangString message)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
Diff
public Diff()
Method Detail
showMessage
public static void showMessage(javalangString message)
doDiffer
public static boolean doDiffer(javaioFile[] files)
main
public static void main(javalangString[] args)
Class Huff
javalangObject
Huffpublic class Huffextends javalangObject
Mainlaunch program for Huff assignment A better comment than this is warranted
Constructor Summary
Huff()
Method Summary
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
Huff
public Huff()
Method Detail
main
public static void main(javalangString[] args)
Class HuffMark
javalangObject
HuffMarkpublic class HuffMarkextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourOpenChooser
Constructor Summary
HuffMark()
Method Summary
void compress(javaioFile f)
void doMark()
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourOpenChooser
protected static javaxswingJFileChooser ourOpenChooser
Constructor Detail
HuffMark
public HuffMark()
Method Detail
compress
public void compress(javaioFile f) throws javaioIOException
Throws javaioIOException
doMark
public void doMark()
throws javaioIOExceptionThrows javaioIOException
main
public static void main(javalangString[] args) throws javaioIOException
Throws javaioIOException
Class HuffViewer
javalangObject
javaawtComponent
javaawtContainer
javaawtWindow
javaawtFrame
javaxswingJFrame
HuffViewerAll Implemented Interfaces
javaawtimageImageObserver javaawtMenuContainer javaioSerializable javaxaccessibilityAccessible javaxswingRootPaneContainer javaxswingWindowConstants
public class HuffViewerextends javaxswingJFrame
The GUIView for Huffman coding assignment Clients communicate with this view by attaching a model and then using the menu choicesoptions that are part of the GUI Thus client code that fails to call setModel will almost certainly not work and generate null pointer problems because the viewGUI will not have an associated model
See AlsoSerialized Form
Nested Class Summary
Nested classesinterfaces inherited from class javaxswingJFrame
javaxswingJFrameAccessibleJFrame
Nested classesinterfaces inherited from class javaawtFrame
javaawtFrameAccessibleAWTFrame
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
Diffpublic class Diffextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourChooser
Constructor Summary
Diff()
Method Summary
static boolean doDiffer(javaioFile[] files)
static void main(javalangString[] args)
static void showMessage(javalangString message)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
Diff
public Diff()
Method Detail
showMessage
public static void showMessage(javalangString message)
doDiffer
public static boolean doDiffer(javaioFile[] files)
main
public static void main(javalangString[] args)
Class Huff
javalangObject
Huffpublic class Huffextends javalangObject
Mainlaunch program for Huff assignment A better comment than this is warranted
Constructor Summary
Huff()
Method Summary
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
Huff
public Huff()
Method Detail
main
public static void main(javalangString[] args)
Class HuffMark
javalangObject
HuffMarkpublic class HuffMarkextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourOpenChooser
Constructor Summary
HuffMark()
Method Summary
void compress(javaioFile f)
void doMark()
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourOpenChooser
protected static javaxswingJFileChooser ourOpenChooser
Constructor Detail
HuffMark
public HuffMark()
Method Detail
compress
public void compress(javaioFile f) throws javaioIOException
Throws javaioIOException
doMark
public void doMark()
throws javaioIOExceptionThrows javaioIOException
main
public static void main(javalangString[] args) throws javaioIOException
Throws javaioIOException
Class HuffViewer
javalangObject
javaawtComponent
javaawtContainer
javaawtWindow
javaawtFrame
javaxswingJFrame
HuffViewerAll Implemented Interfaces
javaawtimageImageObserver javaawtMenuContainer javaioSerializable javaxaccessibilityAccessible javaxswingRootPaneContainer javaxswingWindowConstants
public class HuffViewerextends javaxswingJFrame
The GUIView for Huffman coding assignment Clients communicate with this view by attaching a model and then using the menu choicesoptions that are part of the GUI Thus client code that fails to call setModel will almost certainly not work and generate null pointer problems because the viewGUI will not have an associated model
See AlsoSerialized Form
Nested Class Summary
Nested classesinterfaces inherited from class javaxswingJFrame
javaxswingJFrameAccessibleJFrame
Nested classesinterfaces inherited from class javaawtFrame
javaawtFrameAccessibleAWTFrame
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
main
public static void main(javalangString[] args)
Class Huff
javalangObject
Huffpublic class Huffextends javalangObject
Mainlaunch program for Huff assignment A better comment than this is warranted
Constructor Summary
Huff()
Method Summary
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
Huff
public Huff()
Method Detail
main
public static void main(javalangString[] args)
Class HuffMark
javalangObject
HuffMarkpublic class HuffMarkextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourOpenChooser
Constructor Summary
HuffMark()
Method Summary
void compress(javaioFile f)
void doMark()
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourOpenChooser
protected static javaxswingJFileChooser ourOpenChooser
Constructor Detail
HuffMark
public HuffMark()
Method Detail
compress
public void compress(javaioFile f) throws javaioIOException
Throws javaioIOException
doMark
public void doMark()
throws javaioIOExceptionThrows javaioIOException
main
public static void main(javalangString[] args) throws javaioIOException
Throws javaioIOException
Class HuffViewer
javalangObject
javaawtComponent
javaawtContainer
javaawtWindow
javaawtFrame
javaxswingJFrame
HuffViewerAll Implemented Interfaces
javaawtimageImageObserver javaawtMenuContainer javaioSerializable javaxaccessibilityAccessible javaxswingRootPaneContainer javaxswingWindowConstants
public class HuffViewerextends javaxswingJFrame
The GUIView for Huffman coding assignment Clients communicate with this view by attaching a model and then using the menu choicesoptions that are part of the GUI Thus client code that fails to call setModel will almost certainly not work and generate null pointer problems because the viewGUI will not have an associated model
See AlsoSerialized Form
Nested Class Summary
Nested classesinterfaces inherited from class javaxswingJFrame
javaxswingJFrameAccessibleJFrame
Nested classesinterfaces inherited from class javaawtFrame
javaawtFrameAccessibleAWTFrame
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
HuffMarkpublic class HuffMarkextends javalangObject
Field Summary
protected static javaxswingJFileChooser
ourOpenChooser
Constructor Summary
HuffMark()
Method Summary
void compress(javaioFile f)
void doMark()
static void main(javalangString[] args)
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
ourOpenChooser
protected static javaxswingJFileChooser ourOpenChooser
Constructor Detail
HuffMark
public HuffMark()
Method Detail
compress
public void compress(javaioFile f) throws javaioIOException
Throws javaioIOException
doMark
public void doMark()
throws javaioIOExceptionThrows javaioIOException
main
public static void main(javalangString[] args) throws javaioIOException
Throws javaioIOException
Class HuffViewer
javalangObject
javaawtComponent
javaawtContainer
javaawtWindow
javaawtFrame
javaxswingJFrame
HuffViewerAll Implemented Interfaces
javaawtimageImageObserver javaawtMenuContainer javaioSerializable javaxaccessibilityAccessible javaxswingRootPaneContainer javaxswingWindowConstants
public class HuffViewerextends javaxswingJFrame
The GUIView for Huffman coding assignment Clients communicate with this view by attaching a model and then using the menu choicesoptions that are part of the GUI Thus client code that fails to call setModel will almost certainly not work and generate null pointer problems because the viewGUI will not have an associated model
See AlsoSerialized Form
Nested Class Summary
Nested classesinterfaces inherited from class javaxswingJFrame
javaxswingJFrameAccessibleJFrame
Nested classesinterfaces inherited from class javaawtFrame
javaawtFrameAccessibleAWTFrame
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
throws javaioIOExceptionThrows javaioIOException
main
public static void main(javalangString[] args) throws javaioIOException
Throws javaioIOException
Class HuffViewer
javalangObject
javaawtComponent
javaawtContainer
javaawtWindow
javaawtFrame
javaxswingJFrame
HuffViewerAll Implemented Interfaces
javaawtimageImageObserver javaawtMenuContainer javaioSerializable javaxaccessibilityAccessible javaxswingRootPaneContainer javaxswingWindowConstants
public class HuffViewerextends javaxswingJFrame
The GUIView for Huffman coding assignment Clients communicate with this view by attaching a model and then using the menu choicesoptions that are part of the GUI Thus client code that fails to call setModel will almost certainly not work and generate null pointer problems because the viewGUI will not have an associated model
See AlsoSerialized Form
Nested Class Summary
Nested classesinterfaces inherited from class javaxswingJFrame
javaxswingJFrameAccessibleJFrame
Nested classesinterfaces inherited from class javaawtFrame
javaawtFrameAccessibleAWTFrame
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
Nested classesinterfaces inherited from class javaawtWindow
javaawtWindowAccessibleAWTWindow
Nested classesinterfaces inherited from class javaawtContainer
javaawtContainerAccessibleAWTContainer
Nested classesinterfaces inherited from class javaawtComponent
javaawtComponentAccessibleAWTComponent javaawtComponentBaselineResizeBehavior javaawtComponentBltBufferStrategy javaawtComponentFlipBufferStrategy
Field Summary
protected javaioFile myFile
protected javaxswingJTextField
myMessage
protected IHuffProcessor myModel
protected javaxswingJTextArea
myOutput
protected javalangString myTitle
protected static javaxswingJFileChooser
ourChooser
Fields inherited from class javaxswingJFrame
accessibleContext EXIT_ON_CLOSE rootPane rootPaneCheckingEnabled
Fields inherited from class javaawtFrame
CROSSHAIR_CURSOR DEFAULT_CURSOR E_RESIZE_CURSOR HAND_CURSOR ICONIFIED MAXIMIZED_BOTH MAXIMIZED_HORIZ MAXIMIZED_VERT MOVE_CURSOR N_RESIZE_CURSOR NE_RESIZE_CURSOR NORMAL NW_RESIZE_CURSOR S_RESIZE_CURSOR SE_RESIZE_CURSOR SW_RESIZE_CURSOR TEXT_CURSOR W_RESIZE_CURSOR WAIT_CURSOR
Fields inherited from class javaawtComponent
BOTTOM_ALIGNMENT CENTER_ALIGNMENT LEFT_ALIGNMENT RIGHT_ALIGNMENT TOP_ALIGNMENT
Fields inherited from interface javaxswingWindowConstants
DISPOSE_ON_CLOSE DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE
Fields inherited from interface javaawtimageImageObserver
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
ABORT ALLBITS ERROR FRAMEBITS HEIGHT PROPERTIES SOMEBITS WIDTH
Constructor Summary
HuffViewer(javalangString title)
Method Summary
protected javaioFile
doRead()
protected javaxswingJMenu
makeFileMenu()
protected void makeMenus()
protected javaxswingJPanel
makeMessage()
protected javaxswingJMenu
makeOptionsMenu()
protected javaxswingJPanel
makeOutput()
void setModel(IHuffProcessor model) Associates this view with the given model
void showError(javalangString s) Show a modal-dialog indicating an error the user must dismiss the displayed dialog
void showMessage(javalangString s) Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore
void update(javautilCollection elements) To be called by modelclient code to display strings in the GUI
Methods inherited from class javaxswingJFrame
addImpl createRootPane frameInit getAccessibleContext getContentPane getDefaultCloseOperation getGlassPane getGraphics getJMenuBar getLayeredPane getRootPane getTransferHandler isDefaultLookAndFeelDecorated isRootPaneCheckingEnabled paramString processWindowEvent remove repaint setContentPane setDefaultCloseOperation setDefaultLookAndFeelDecorated setGlassPane setIconImage setJMenuBar setLayeredPane setLayout setRootPane setRootPaneCheckingEnabled setTransferHandler update
Methods inherited from class javaawtFrame
addNotify getCursorType getExtendedState getFrames getIconImage getMaximizedBounds getMenuBar getState getTitle isResizable isUndecorated remove removeNotify setCursor setExtendedState setMaximizedBounds setMenuBar setResizable setState setTitle setUndecorated
Methods inherited from class javaawtWindow
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
addPropertyChangeListener addPropertyChangeListener addWindowFocusListener addWindowListener addWindowStateListener applyResourceBundle applyResourceBundle createBufferStrategy createBufferStrategy dispose getBufferStrategy getFocusableWindowState getFocusCycleRootAncestor getFocusOwner getFocusTraversalKeys getGraphicsConfiguration getIconImages getInputContext getListeners getLocale getModalExclusionType getMostRecentFocusOwner getOwnedWindows getOwner getOwnerlessWindows getToolkit getWarningString getWindowFocusListeners getWindowListeners getWindows getWindowStateListeners hide isActive isAlwaysOnTop isAlwaysOnTopSupported isFocusableWindow isFocusCycleRoot isFocused isLocationByPlatform isShowing pack postEvent processEvent processWindowFocusEvent processWindowStateEvent removeWindowFocusListener removeWindowListener removeWindowStateListener reshape setAlwaysOnTop setBounds setBounds setCursor setFocusableWindowState setFocusCycleRoot setIconImages setLocationByPlatform setLocationRelativeTo setMinimumSize setModalExclusionType setSize setSize setVisible show toBack toFront
Methods inherited from class javaawtContainer
add add add add add addContainerListener applyComponentOrientation areFocusTraversalKeysSet countComponents deliverEvent doLayout findComponentAt findComponentAt getAlignmentX getAlignmentY getComponent getComponentAt getComponentAt getComponentCount getComponents getComponentZOrder getContainerListeners getFocusTraversalPolicy getInsets getLayout getMaximumSize getMinimumSize getMousePosition getPreferredSize insets invalidate isAncestorOf isFocusCycleRoot isFocusTraversalPolicyProvider isFocusTraversalPolicySet layout list list locate minimumSize paint paintComponents preferredSize print printComponents processContainerEvent remove removeAll removeContainerListener setComponentZOrder setFocusTraversalKeys setFocusTraversalPolicy setFocusTraversalPolicyProvider setFont transferFocusBackward transferFocusDownCycle validate validateTree
Methods inherited from class javaawtComponent
action add addComponentListener addFocusListener addHierarchyBoundsListener addHierarchyListener addInputMethodListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener bounds checkImage checkImage coalesceEvents contains contains createImage createImage createVolatileImage createVolatileImage disable disableEvents dispatchEvent enable enable enableEvents enableInputMethods firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange firePropertyChange getBackground getBaseline getBaselineResizeBehavior getBounds getBounds getColorModel getComponentListeners getComponentOrientation getCursor getDropTarget getFocusListeners getFocusTraversalKeysEnabled getFont getFontMetrics getForeground getHeight getHierarchyBoundsListeners getHierarchyListeners getIgnoreRepaint getInputMethodListeners getInputMethodRequests getKeyListeners getLocation getLocation getLocationOnScreen getMouseListeners getMouseMotionListeners getMousePosition getMouseWheelListeners getName getParent getPeer getPropertyChangeListeners getPropertyChangeListeners getSize getSize getTreeLock getWidth getX getY gotFocus handleEvent hasFocus imageUpdate inside isBackgroundSet isCursorSet isDisplayable isDoubleBuffered isEnabled isFocusable isFocusOwner isFocusTraversable isFontSet isForegroundSet isLightweight isMaximumSizeSet isMinimumSizeSet isOpaque isPreferredSizeSet isValid isVisible keyDown keyUp list list list location lostFocus mouseDown mouseDrag mouseEnter mouseExit mouseMove mouseUp move nextFocus paintAll prepareImage prepareImage printAll processComponentEvent processFocusEvent processHierarchyBoundsEvent processHierarchyEvent processInputMethodEvent processKeyEvent processMouseEvent processMouseMotionEvent processMouseWheelEvent removeComponentListener removeFocusListener removeHierarchyBoundsListener removeHierarchyListener removeInputMethodListener removeKeyListener removeMouseListener removeMouseMotionListener removeMouseWheelListener removePropertyChangeListener removePropertyChangeListener repaint repaint repaint requestFocus requestFocus requestFocusInWindow requestFocusInWindow resize resize setBackground setComponentOrientation setDropTarget setEnabled setFocusable setFocusTraversalKeysEnabled setForeground setIgnoreRepaint
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
setLocale setLocation setLocation setMaximumSize setName setPreferredSize show size toString transferFocus transferFocusUpCycle
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll wait wait wait
Methods inherited from interface javaawtMenuContainer
getFont postEvent
Field Detail
myOutput
protected javaxswingJTextArea myOutput
myModel
protected IHuffProcessor myModel
myTitle
protected javalangString myTitle
myMessage
protected javaxswingJTextField myMessage
myFile
protected javaioFile myFile
ourChooser
protected static javaxswingJFileChooser ourChooser
Constructor Detail
HuffViewer
public HuffViewer(javalangString title)
Method Detail
setModel
public void setModel(IHuffProcessor model)Associates this view with the given model The GUIView will attach itself to the model so that communication between the view and the model as well as vice versa is supported Parameters
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
model - is the model for this view
makeMessage
protected javaxswingJPanel makeMessage()
makeOutput
protected javaxswingJPanel makeOutput()
doRead
protected javaioFile doRead()
makeOptionsMenu
protected javaxswingJMenu makeOptionsMenu()
makeFileMenu
protected javaxswingJMenu makeFileMenu()
makeMenus
protected void makeMenus()
update
public void update(javautilCollection elements)To be called by modelclient code to display strings in the GUI Each object in parameter elements will be displayed as a string in this view Parameterselements - is source of objects that will be displayed each objects toString method wil be called to display
showMessage
public void showMessage(javalangString s)Display a text message in the view (eg in the small text area at the bottom of the GUI) thus a modeless message the user can ignore Parameterss - is the message displayed
showError
public void showError(javalangString s)Show a modal-dialog indicating an error the user must dismiss the displayed dialog Parameterss - is the error-message displayed
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
Interface IHuffConstants
All Known Subinterfaces IHuffProcessor
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffConstants
Global constants used in HuffUnhuff Clients needing these values should implement this interface or access the values directly eg as IHuffConstantsBITS_PER_WORD However implementing the interface is preferred in which case the values can be accessed simply as BITS_PER_WORD for example
Field Summary
static int ALPH_SIZE The size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD
static int BITS_PER_INT The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages
static int BITS_PER_WORD The standard number of bits per chunkword when huffing
static int MAGIC_NUMBER Isolate the magic number in one place
static int PSEUDO_EOF The value of the PSEUDO_EOF character
Field Detail
BITS_PER_WORD
static final int BITS_PER_WORDThe standard number of bits per chunkword when huffing See AlsoConstant Field Values
ALPH_SIZE
static final int ALPH_SIZEThe size of the alphabet given the number of bits per chunk this should be 2^BITS_PER_WORD See AlsoConstant Field Values
BITS_PER_INT
static final int BITS_PER_INT
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
The standard number of bits needed to representstore an int this is 32 in Java and nearly all other languages See AlsoConstant Field Values
PSEUDO_EOF
static final int PSEUDO_EOFThe value of the PSEUDO_EOF character This is one-more than the maximum value of a legal BITS_PER_WORD-bit character See AlsoConstant Field Values
MAGIC_NUMBER
static final int MAGIC_NUMBERIsolate the magic number in one place See AlsoConstant Field Values
Interface IHuffProcessor
All Superinterfaces IHuffConstants
All Known Implementing Classes SimpleHuffProcessor
public interface IHuffProcessorextends IHuffConstants
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Method Detail
setViewer
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
void setViewer(HuffViewer viewer)Make sure this model communicates with some view Parametersviewer - is the view for communicating
preprocessCompress
int preprocessCompress(javaioInputStream in) throws javaioIOException
Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Parametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
compress
int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Parametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
uncompress
int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Uncompress a previously compressed stream in writing the uncompressed bitsdata to out Parametersin - is the previously compressed data (not a BitInputStream)out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class SimpleHuffProcessor
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
javalangObject
SimpleHuffProcessorAll Implemented Interfaces
IHuffConstants IHuffProcessorpublic class SimpleHuffProcessorextends javalangObjectimplements IHuffProcessor
Field Summary
Fields inherited from interface IHuffConstants
ALPH_SIZE BITS_PER_INT BITS_PER_WORD MAGIC_NUMBER PSEUDO_EOF
Constructor Summary
SimpleHuffProcessor()
Method Summary
int compress(javaioInputStream in javaioOutputStream out boolean force) Compresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call
int preprocessCompress(javaioInputStream in) Preprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work
void setViewer(HuffViewer viewer) Make sure this model communicates with some view
int uncompress(javaioInputStream in javaioOutputStream out) Uncompress a previously compressed stream in writing the uncompressed bitsdata to out
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Constructor Detail
SimpleHuffProcessor
public SimpleHuffProcessor()
Method Detail
compress
public int compress(javaioInputStream in javaioOutputStream out boolean force) throws javaioIOException
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
Description copied from interface IHuffProcessorCompresses input to output where the same InputStream has previously been pre-processed via preprocessCompress storing state used by this call Specified bycompress in interface IHuffProcessorParametersin - is the stream being compressed (not a BitInputStream)out - is bound to a filestream to which bits are written for the compressed file (not a BitOutputStream) Returnsthe number of bits written Throws javaioIOException
preprocessCompress
public int preprocessCompress(javaioInputStream in) throws javaioIOException
Description copied from interface IHuffProcessorPreprocess data so that compression is possible --- count characterscreate treestore state so that a subsequent call to compress will work The InputStream is not a BitInputStream so wrap it int one as needed Specified bypreprocessCompress in interface IHuffProcessorParametersin - is the stream which could be subsequently compressed Returnsnumber of bits saved by compression or some other measure Throws javaioIOException
setViewer
public void setViewer(HuffViewer viewer)Description copied from interface IHuffProcessorMake sure this model communicates with some view Specified bysetViewer in interface IHuffProcessorParametersviewer - is the view for communicating
uncompress
public int uncompress(javaioInputStream in javaioOutputStream out) throws javaioIOException
Description copied from interface IHuffProcessorUncompress a previously compressed stream in writing the uncompressed bitsdata to out Specified byuncompress in interface IHuffProcessorParametersin - is the previously compressed data (not a BitInputStream)
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
out - is the uncompressed filestream Returnsthe number of bits written to the uncompressed filestream Throws javaioIOException
Class TreeNode
javalangObject
TreeNodeAll Implemented Interfaces
javalangComparableltTreeNodegtpublic class TreeNodeextends javalangObjectimplements javalangComparableltTreeNodegt
Utility binary-tree (Huffman tree) node for Huffman coding This is a simple standard binary-tree node implementing the comparable interface based on weight
Field Summary
TreeNode myLeft
TreeNode myRight
int myValue
int myWeight
Constructor Summary
TreeNode(int value int weight) construct leaf node (null children)
TreeNode(int value int weight TreeNode ltree TreeNode rtree) construct internal node (with children)
Method Summary
int compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
Return value based on comparing this TreeNode to another
Methods inherited from class javalangObject
clone equals finalize getClass hashCode notify notifyAll toString wait wait wait
Field Detail
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
Constructor Detail
TreeNode
public TreeNode(int value int weight)
construct leaf node (null children) Parametersvalue - is the value stored in the node (eg character)weight - is used for comparison (eg count of occurrences)
TreeNode
public TreeNode(int value int weight TreeNode ltree TreeNode rtree)
construct internal node (with children) Parametersvalue - is stored as value of nodeweight - is weight of node
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
ltree - is left subtreertree - is right subtree
Method Detail
compareTo
public int compareTo(TreeNode rhs)Return value based on comparing this TreeNode to another Specified bycompareTo in interface javalangComparableltTreeNodegtReturns-1 if this lt o +1 if this gt o and 0 if this == 0
Constant Field Values
ltUnnamedgt
IHuffConstants
public static final int ALPH_SIZE 256
public static final int BITS_PER_INT 32
public static final int BITS_PER_WORD 8
public static final int MAGIC_NUMBER 1234567873
public static final int PSEUDO_EOF 256
- Class BitInputStream
-
- BitInputStream
- BitInputStream
- BitInputStream
- markSupported
- reset
- close
- readBits
- read
-
- Class BitOutputStream
-
- BitOutputStream
- BitOutputStream
- write
- flush
- close
- writeBits
-
- Class Diff
-
- ourChooser
- Diff
- showMessage
- doDiffer
- main
-
- Class Huff
-
- Huff
- main
-
- Class HuffMark
-
- ourOpenChooser
- HuffMark
- compress
- doMark
- main
-
- Class HuffViewer
-
- myOutput
- myModel
- myTitle
- myMessage
- myFile
- ourChooser
- HuffViewer
- setModel
- makeMessage
- makeOutput
- doRead
- makeOptionsMenu
- makeFileMenu
- makeMenus
- update
- showMessage
- showError
-
- Interface IHuffConstants
-
- BITS_PER_WORD
- ALPH_SIZE
- BITS_PER_INT
- PSEUDO_EOF
- MAGIC_NUMBER
-
- Interface IHuffProcessor
-
- setViewer
- preprocessCompress
- compress
- uncompress
-
- Class SimpleHuffProcessor
-
- SimpleHuffProcessor
- compress
- preprocessCompress
- setViewer
- uncompress
-
- Class TreeNode
-
- myValue
- myWeight
- myLeft
- myRight
- TreeNode
- TreeNode
- compareTo
-
- Constant Field Values
-
top related