com.guiffy.inside
Class GuiffyUPatch

java.lang.Object
  extended by java.lang.Thread
      extended by com.guiffy.inside.GuiffyUPatch
All Implemented Interfaces:
java.lang.Runnable

public class GuiffyUPatch
extends java.lang.Thread

Class GuiffyUPatch is the Unified Diff Patch class for including Patch inside Java applications. GuiffyUPatch extends Thread.

GuiffyUPatch scans the Patch file for the changes made to the Original file. Changes made to other files are skipped over. GuiffyUPatch scans both backward and forward to find the matching context for a change. If GuiffyUPatch cannot find the context for a change, it writes that change (also called a hunk) to a reject file. The reject file is normally the name of the Output file plus a .rej suffix.

End-of-Line differences are ignored when matching context. Properties are provided for specifying End-of-Line and Encoding formats.

Example code :
The following instantiates a GuiffyUPatch object with all its properties set to default.

import com.guiffy.inside.*;
      ...
      GuiffyUPatch uPatch = new GuiffyUPatch( );
Then, we set GuiffyUPatch's properties (at least the 3 filenames).
      uPatch.setOrgFile(orgFileName);
      uPatch.setPatFile(patFileName);
      uPatch.setOutFile(outFileName);
Then, we run GuiffyUPatch and wait for it to finish.
      try {
          uPatch.join();
      } catch (InterruptedException e) { }

Then, we check the return status and get info on chunks (changes) applied.
      int rstat = uPatch.getStatus();
      int noChunks = uPatch.getNumberofChunks();
      int noAppChunks = uPatch.getNumberofAppliedChunks();
      int noNotChunks = uPatch.getNumberofNotAppliedChunks();
      ...

Version:
11.1 -- developed in January, 2015
Author:
Guiffy Software, Inc. by Bill Ritcher
See Also:
Thread

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int CANT_FIND_ORGFILE
           
static int CANT_FIND_PATFILE
           
static int CANT_READ_ORGFILE
           
static int CANT_READ_PATFILE
           
static int CANT_WRIT_OUTFILE
           
static int CONTEXT
           
static int EDIT
           
static int ENCODING_NOTAVAIL
           
static int ERRORIS_EXCEPTION
           
static int EVALPER_ISEXPIRED
           
static int ISAFOLDER_ORGFILE
           
static int ISAFOLDER_PATFILE
           
static int NORMAL
           
static int OK
           
static int PATFILE_NOTUNIFID
           
static int UNIFIED
           
static int UPATCH_FNNOTFOUND
           
static int UPATCH_NOTALLOWED
           
static int UPATCH_NOTCOMPLET
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
GuiffyUPatch()
           
 
Method Summary
 int getNumberofAppliedChunks()
          Returns the number of applied patch chunks.
 int getNumberofChunks()
          Returns the number of patch chunks.
 int getNumberofNotAppliedChunks()
          Returns the number of Not applied patch chunks.
 int getStatus()
          Returns Status of GuiffyUPatch Run.
 java.util.List<com.guiffy.inside.UnifiedChunk> getUnifiedChunksList()
          Returns the List of Unified Chunks.
 void run()
           
 void setEOLOption(java.lang.String eolopt)
          Sets Write EOLs option for Output file.
 void setFileEncoding(java.lang.String encods)
          Sets File Encoding for Original, Patch, and Output files.
 void setGuiffyExit(GuiffyExit hook)
          Sets the GuiffyExit hook of the GuiffyUPatch If set to null, a previously added GuiffyExit hook will be removed.
 void setIgnoreWhitespace(boolean ignwhi)
          Sets IgnoreWhitespace option true or false.
 void setOEMLicenseKey(java.io.ByteArrayInputStream bais)
          Set License Key based on special OEMKey ByteArrayInputStream
 void setOrgFile(java.lang.String orgname)
          Sets the Original File Name.
 void setOrgFileEncoding(java.lang.String encods)
          Sets File Encoding for Original file.
 void setOutFile(java.lang.String outname)
          Sets the Output File Name.
 void setOutFileEncoding(java.lang.String encods)
          Sets File Encoding for Output file.
 void setPatFile(java.lang.String patname)
          Sets the Patch File Name.
 void setPatFileEncoding(java.lang.String encods)
          Sets File Encoding for Patch file.
 void setRejectsOut(boolean rejout)
          Sets Rejects Output option true or false.
 void setRejFile(java.lang.String rejname)
          Sets the Rejects File Name.
 void setSilentOption(boolean silopt)
          Sets Silent Output option true or false.
 void setVerboseOption(boolean veropt)
          Sets Verbose Output option true or false.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OK

public static final int OK
See Also:
Constant Field Values

CANT_FIND_ORGFILE

public static final int CANT_FIND_ORGFILE
See Also:
Constant Field Values

CANT_FIND_PATFILE

public static final int CANT_FIND_PATFILE
See Also:
Constant Field Values

CANT_READ_ORGFILE

public static final int CANT_READ_ORGFILE
See Also:
Constant Field Values

CANT_READ_PATFILE

public static final int CANT_READ_PATFILE
See Also:
Constant Field Values

CANT_WRIT_OUTFILE

public static final int CANT_WRIT_OUTFILE
See Also:
Constant Field Values

ISAFOLDER_ORGFILE

public static final int ISAFOLDER_ORGFILE
See Also:
Constant Field Values

ISAFOLDER_PATFILE

public static final int ISAFOLDER_PATFILE
See Also:
Constant Field Values

PATFILE_NOTUNIFID

public static final int PATFILE_NOTUNIFID
See Also:
Constant Field Values

ENCODING_NOTAVAIL

public static final int ENCODING_NOTAVAIL
See Also:
Constant Field Values

ERRORIS_EXCEPTION

public static final int ERRORIS_EXCEPTION
See Also:
Constant Field Values

EVALPER_ISEXPIRED

public static final int EVALPER_ISEXPIRED
See Also:
Constant Field Values

UPATCH_NOTALLOWED

public static final int UPATCH_NOTALLOWED
See Also:
Constant Field Values

UPATCH_NOTCOMPLET

public static final int UPATCH_NOTCOMPLET
See Also:
Constant Field Values

UPATCH_FNNOTFOUND

public static final int UPATCH_FNNOTFOUND
See Also:
Constant Field Values

NORMAL

public static final int NORMAL
See Also:
Constant Field Values

EDIT

public static final int EDIT
See Also:
Constant Field Values

CONTEXT

public static final int CONTEXT
See Also:
Constant Field Values

UNIFIED

public static final int UNIFIED
See Also:
Constant Field Values
Constructor Detail

GuiffyUPatch

public GuiffyUPatch()
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getStatus

public int getStatus()
Returns Status of GuiffyUPatch Run.

Returns:
the int value that indicates the status of run:
   OK = 0;
   CANT_FIND_ORGFILE = 1;  // Can't find Original file
   CANT_FIND_PATFILE = 2;  // Can't find Patch file
   CANT_READ_ORGFILE = 4;  // Can't read Original file
   CANT_READ_PATFILE = 5;  // Can't read Patch file
   CANT_WRIT_OUTFILE = 7;  // Can't write/create Output file
   ISAFOLDER_ORGFILE = 8;  // Original file is a folder
   ISAFOLDER_PATFILE = 9;  // Patch file is a folder
   ENCODING_NOTAVAIL = 11; // File Encoding specified NA
   ERRORIS_EXCEPTION = 12; // Exception
                           // (perhaps, encoding format)
   EVALPER_ISEXPIRED = 13; // Evaluation period has expired
   UPATCH_NOTALLOWED = 15; // eXpert license required
   UPATCH_NOTCOMPLET = 16; // One or more changes(chunks) not applied
   UPATCH_FNNOTFOUND = 17; // Patchs for Original file not found in
                              Patch file

getNumberofChunks

public int getNumberofChunks()
Returns the number of patch chunks.

Returns:
the integer value - the number of patch chunks

getNumberofAppliedChunks

public int getNumberofAppliedChunks()
Returns the number of applied patch chunks.

Returns:
the integer value - the number of applied patch chunks

getNumberofNotAppliedChunks

public int getNumberofNotAppliedChunks()
Returns the number of Not applied patch chunks.

Returns:
the integer value - the number of Not applied patch chunks

getUnifiedChunksList

public java.util.List<com.guiffy.inside.UnifiedChunk> getUnifiedChunksList()
Returns the List of Unified Chunks.

Returns:
the list of unified chunk objects

setGuiffyExit

public void setGuiffyExit(GuiffyExit hook)
Sets the GuiffyExit hook of the GuiffyUPatch If set to null, a previously added GuiffyExit hook will be removed.

See Also:
GuiffyExit

setOEMLicenseKey

public void setOEMLicenseKey(java.io.ByteArrayInputStream bais)
Set License Key based on special OEMKey ByteArrayInputStream


setOrgFile

public void setOrgFile(java.lang.String orgname)
Sets the Original File Name.

Parameters:
orgname - the Original File name as a complete path.

setPatFile

public void setPatFile(java.lang.String patname)
Sets the Patch File Name.

Parameters:
patname - the Patch File name as a complete path.

setOutFile

public void setOutFile(java.lang.String outname)
Sets the Output File Name.

Parameters:
outname - the Output File name as a complete path.

setRejFile

public void setRejFile(java.lang.String rejname)
Sets the Rejects File Name.

Parameters:
rejname - the Rejects File name as a complete path.

setFileEncoding

public void setFileEncoding(java.lang.String encods)
Sets File Encoding for Original, Patch, and Output files. Default is the format of the Locale operating environment.

Parameters:
encods - the String value of the Encoding such as "ASCII", "UTF8", "SJIS", "Cp500" (for EBCDIC) etc. - Over 100 formats supported.

setOrgFileEncoding

public void setOrgFileEncoding(java.lang.String encods)
Sets File Encoding for Original file. Default is the format of the Locale operating environment.

Parameters:
encods - the String value of the Encoding such as "ASCII", "UTF8", "SJIS", "Cp500" (for EBCDIC) etc. - Over 100 formats supported.

setPatFileEncoding

public void setPatFileEncoding(java.lang.String encods)
Sets File Encoding for Patch file. Default is the format of the Locale operating environment.

Parameters:
encods - the String value of the Encoding such as "ASCII", "UTF8", "SJIS", "Cp500" (for EBCDIC) etc. - Over 100 formats supported.

setOutFileEncoding

public void setOutFileEncoding(java.lang.String encods)
Sets File Encoding for Output file. Default is the format of the Locale operating environment.

Parameters:
encods - the String value of the Encoding such as "ASCII", "UTF8", "SJIS", "Cp500" (for EBCDIC) etc. - Over 100 formats supported.

setIgnoreWhitespace

public void setIgnoreWhitespace(boolean ignwhi)
Sets IgnoreWhitespace option true or false. Default is false.

Parameters:
ignwhi - the boolean value that determines whether whitespace differences are ignored during the patch.

setRejectsOut

public void setRejectsOut(boolean rejout)
Sets Rejects Output option true or false. Default is true.

Parameters:
rejout - the boolean value that determines whether rejects are written to Rejects file.

setSilentOption

public void setSilentOption(boolean silopt)
Sets Silent Output option true or false. Default is false.

Parameters:
silopt - the boolean value that suppresses info to stdout

setVerboseOption

public void setVerboseOption(boolean veropt)
Sets Verbose Output option true or false. Default is false.

Parameters:
veropt - the boolean value that writes addl info to stderr

setEOLOption

public void setEOLOption(java.lang.String eolopt)
Sets Write EOLs option for Output file. Default is the format of the operating environment.

Parameters:
eolopt - the String value of "DOS", "MacOS" or "Unix" specifies the format for writing End-Of-Lines in Output File.