public static void TempPreProcessor_Fixed(String input, String output){
BufferedReader reader = null;
BufferedWriter writer = null;
try
{
String inputfilename = input;
String outputfilename = output;
reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(inputfilename)));
writer = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(outputfilename)));
String thisLine = null;
//line 1
if((thisLine =reader.readLine()) != null)
writer.write("AA,"+thisLine+"\n");
//line 2-4
for(int i = 0; i<3; i++){
if((thisLine =reader.readLine()) != null)
writer.write(thisLine+"\n");
}
//remaining lines
while((thisLine=reader.readLine()) != null){
//add AB to start of line
writer.write("AB,"+thisLine+"\n");
//copy with no change
if((thisLine=reader.readLine()) != null)
writer.write(thisLine+"\n");
}
}catch(Exception e){
throw new ServiceException("TempPreProcessor: Unknown errors: " + e.toString());
}finally{
try{
if(writer != null) writer.flush();
if(reader != null) reader.close();
if(writer != null) writer.close();
reader=null; writer=null;
}catch(Exception e){
throw new ServiceException("TempPreProcessor: Unknown errors: " + e.toString());
}
}
}
Thursday, February 24, 2011
Java Read/Write Fixed Length file sample
Posted by
techgeek168
at
2:33 PM
0
comments
Labels: java
Java Read/Write CSV file sample
public static void TempPreProcessor_CSV(String input, String output){
//IDataSharedCursor idc = pipeline.getSharedCursor();
BufferedReader reader = null;
BufferedWriter writer = null;
try
{
String inputfilename = input;
String outputfilename = output;
reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(inputfilename)));
writer = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(outputfilename)));
int lineNum = 1;
String checkNum = "";
String thisLine = "";
// comma, which is not enclosed in quotes
String delims = ",(?=([^\"]*\"[^\"]*\")*[^\"]*$)";
while((thisLine=reader.readLine()) != null){// till end of file
StringBuffer sb = new StringBuffer();
if(thisLine.trim().equals(""))
continue; // ignore blank lines
if (lineNum++ == 1){
sb.append(thisLine + "\n");
writer.write(sb.toString());
continue;
}
String[] thisTokens = thisLine.split(delims);
if (!checkNum.equalsIgnoreCase(thisTokens[0].toString())){
checkNum = thisTokens[0].toString();
sb.append("AA," + thisLine);
}else{
sb.append("AB," + thisLine);
}
sb.append("\n");
writer.write(sb.toString());
}
}catch(Exception e){
//throw new ServiceException(
// "TempPreProcessor: Unknown errors: " + e.toString());
}finally{
try {
if(writer != null) writer.flush();
if(reader != null) reader.close();
if(writer != null) writer.close();
reader=null;
writer=null;
//idc.destroy();
}catch(Exception e){
//throw new ServiceException(
// "TempPreProcessor: Unknown errors: " + e.toString());
}
}
}
Posted by
techgeek168
at
12:46 PM
0
comments
Labels: java
Java Date Format
public static String parseDate(String inDate, String fmFormat, String toFormat){
SimpleDateFormat fmFormatter = new SimpleDateFormat(fmFormat);
SimpleDateFormat toFormatter = new SimpleDateFormat(toFormat);
if ( inDate == null ) return ""; // To avoid java.lang.NullPointerException
if ( inDate.length() == 0 ) return ""; // Taking care of empty string.
Date fromDate = null;
try {
fromDate = (Date) fmFormatter.parse(inDate);
} catch (ParseException e) {
e.printStackTrace();
}
return toFormatter.format(fromDate);
}
Posted by
techgeek168
at
12:38 PM
0
comments
Labels: java
Java Switch Statement
int boolInt=1;
switch (boolInt){
case 0: System.out.println("true = 0"); break;
case 1: System.out.println("false = 1"); break;
default: System.out.println("Invalid"); break;
}
// In Java SE 7 and later, you can use a String object in the switch statement's expression
String boolStr = "true";
switch (boolStr.toLowerCase()){
case "true": System.out.println("0 = true"); break;
case "false": System.out.println("1 = false"); break;
default: System.out.println(" Not 0/1 = false"); break;
}
Posted by
techgeek168
at
11:30 AM
0
comments
Labels: java
Wednesday, January 12, 2011
How to move a tag to the tip of a branch?
CVS allows an existing tag to be moved to the tip of a branch in one operation (tag -F) so with this method we don't have to execute an additional “cvs rtag –d” operation to clean out the tag and then “cvs tag”.
Step 1: View the current Graph Selection: Right click on file2.txt file -> click on Graph selection…
Step 2: Update file2.txt and commit it to version 1.2.2.2
Step 3: Repeat Step 1 – Note that we want to move R-0-1-1 to version 1.2.2.2.
Step 4: Moving R-0-1-1: Admin -> Command Line … -> Enter “cvs tag –F R-0-1-1” in Command line settings window -> click on OK button in Command line settings window.
Step 5: Verify Changes:
cvs tag -F R-0-1-1 T file2.txt *****CVS exited normally with code 0*****Or repeat Step 1:
Posted by
techgeek168
at
11:19 AM
0
comments
How to remove files or directories in CVS?
To remove files, you first schedule the files for removal, and then commit the change:
1. Select the file or files that you want to remove.
2. Click the right mouse button on the selection, and choose the Remove selection menu item. (See the Note below if you can’t find the Remove select menu item.)
3. As the files are only marked for removal, you have to commit them to remove them from the repository. See Sending Your Changes to CVS if you don't know how to commit.
Note: If you can’t find the Remove selection menu item, then: Right click on any file -> Select “Customize this menu…” -> Add the “Remove selection” item on Customize menus window. -> Click OK.
The files will now be removed from the repository. Note that files are not physically removed, but rather marked as "dead". By this way it will still be possible to retrieve the files if you choose to check out an old version of the module.
Removing directories is another story. CVS will optionally remove empty directories when you update one of its parent directories. If you want to get rid of an empty directory, do the following:
1. Select the parent directory of the empty directory you want to remove.
2. Click the right mouse button on the selection, and choose the Update selection menu item.
3. Select the Globals tab.
4. Make sure Prune (remove) empty directories is checked (it is by default).
5. Press the OK button.
The directory will be removed if all its files were previously removed from your local copy and from the repository.
Posted by
techgeek168
at
11:11 AM
0
comments
Labels: SourceControl
Using Branch with WinCVS
How to setup a fix branch?
Step 1: Initial Situation: Let’s suppose
A. R-0-1-0 installed in production.
B. The current version of file1.txt is 1.3.
C. We have a production issue now. Meaning we have a bug in release R-0-1-0.
Step 2: Setup fix branch, F-0-1-0, for R-0-1-0 in CVS server.
A. Create -> Select the “Create a branch by module” menu item. -> In Create branch settings window, enter a tag/branch name “F-0-1-0” in the “New branch name” input field. Enter “CVSBranchTest” in the “Module to fork:” field. -> Under “Optionally use this revision/tag/date to create the branch”, check “Fork from this rev./tag” and enter “R-0-1-0”
B. Uncheck “Checkout read-only” option in Globals tab window.
C. Press the OK button
D. Verify the branch creatation: Within CVSBranchMain tree, right click on the file, file1.txt, and select “Graph select” option -> In Local setting window, click on OK button. -> Verify that “F-0-1-0” created as below:
Step 3: Selecting the Fix Branch to Work on:
To start working on a branch instead of the default development line, you have to bind your local copy to the branch. This is needed to make sure that actions such as updates, commits etc. work on the branch rather than on the main line of development.
To prepare your local copy to another branch, do the following:
A. Following Checkout Initial Release Module to checkout CVSBranchTest into CVSBranchF010 directory.
B. Verify F-0-1-0 checkout.
C. After working on file1.txt, right click on file1.txt file and select “Commit selection…” -> Enter the commit comment in the Commit settings window, and then click on OK button.
Step 4: Verify fixed version of the updated file: Right click on file1.txt stored in CVSBranchF010 directory -> Select “Graph selection…” -> Verify a version 1.2.2.1 is created under the F-0-1-0 branch.
Step 5: Repeating a few times for testing…
Step 6: Fix/Patch Release: Create new “R-0-1-1” tag for F-0-1-0 branch.
Create a tag by module… -> Enter the following info into Create tag settings window and then click on OK button.
Step 7: Verify Fix/Patch Release:
Right click on file1.txt stored under CVSBranchF010 folder à Select Graph select and click on OK button on the “Log settings” window.
How to merge fix branch into main?
When you are satisfied with the changes you have done on a branch, you may want those changes to be available on the main line of development. Incorporating changes from one branch to another, is known as merging. To merge from a branch, do the following:Step 1: Right click on CVSBranchMain folder and select “Update selection…” option.
Step 2: Make sure “Create missing directories that exist in the repository” is checked.
Step 3: Select the Merge options tab -> Click the Only this rev./tag radio button -> In the Only this rev./tag input field, enter the tag/branch name,”R-0-1-1”. If you want to merge from a given timestamp in this tag, check the Date radio button and type in your preferred timestamp as well. -> Click on OK button.
Note: Any changes on the branch F-0-1-0 (or tag R-0-1-1) will now be merged into your local copy under CVSBranchMain folder.
How to merge fix branch into main?
When you are satisfied with the changes you have done on a branch, you may want those changes to be available on the main line of development. Incorporating changes from one branch to another, is known as merging. To merge from a branch, do the following:Step 1: Right click on CVSBranchMain folder and select “Update selection…” option.
Step 2: Make sure “Create missing directories that exist in the repository” is checked.
Step 3: Select the Merge options tab -> Click the Only this rev./tag radio button -> In the Only this rev./tag input field, enter the tag/branch name,”R-0-1-1”. If you want to merge from a given timestamp in this tag, check the Date radio button and type in your preferred timestamp as well. -> Click on OK button.
Note: Any changes on the branch F-0-1-0 (or tag R-0-1-1) will now be merged into your local copy under CVSBranchMain folder.
How to resolve conflicts?
Once in a while, the CVS server will report a conflict when you update your files from the repository. A conflict occurs when two or more developers have changed the same few lines of a file. As CVS knows nothing of your project, it leaves resolving the conflicts to the developers. Whenever a conflict is reported, you should open the file in question, and search for lines starting with the string <<<<<<<. The conflicting area is marked like this:You should decide what the code should look like, do the necessary changes, remove the CVS markup, and commit your modifications to the repository.
<<<<<<< filename your changes ======= code merged from repository >>>>>>> revision
If you would like a more graphical diff tool, there are several to go for. Download and install your preferred tool, then go to Admin -> Preferences / WinCvs menu item and check the External diff program checkbox, find your tool and click OK. Then, in the Diff -> Selection menu item, check the Use the external diff checkbox to use it.
cvs -z9 update -P -d -jR-0-1-1 (in directory C:\cygwin\home\hsual\alhsu\AlHome\CVSBranchMain\) RCS file: /opt/cvs/CVSBranchTest/file1.txt,v retrieving revision 1.2 retrieving revision 1.2.2.5 Merging differences between 1.2 and 1.2.2.5 into file1.txt rcsmerge: warning: conflicts during merge *****CVS exited normally with code 0*****
Step 5: Resolving Conflicts
Remove the lines in red below in file1.txt file: Suppose the lines in blue below are correct.
hsual@psgltpe014 $ hsual@psgltpe014 $ pwd /home/hsual/alhsu/AlHome/CVSBranchMain hsual@psgltpe014 $ hsual@psgltpe014 $ ls -a ./ .#file1.txt.1.8* ../ CVS/ file1.txt* file2.txt* file3.txt* hsual@psgltpe014 $ hsual@psgltpe014 $ more file1.txt <<<<<<< file1.txt file1 initial version. Update this file for release R-0-1-0 (Release-Year-Month-Fix/Patch) changed for F-0-1-0 branch. 00.UPDATE 1.4 ======= file1 initial version. Update this file for release R-0-1-0 (Release-Year-Month-Fix/Patch) changed for F-0-1-0 branch. 00. UPDATE 1.2.2.3 >>>>>>> 1.2.2.5 hsual@psgltpe014 $ edit file1.txt hsual@psgltpe014 $ more file1.txt file1 initial version. Update this file for release R-0-1-0 (Release-Year-Month-Fix/Patch) changed for F-0-1-0 branch. 00. UPDATE 1.2.2.3 hsual@psgltpe014 $After editing the file, do a Diff on file1.txt file: Right click on file1.txt file -> Diff selection… -> Select “Compare your local file with another revision/tag/branch/date:” option -> Enter “R-0-1-1” as below:
cvs -z9 diff -r R-0-1-1 file1.txt (in directory C:\cygwin\home\hsual\alhsu\AlHome\CVSBranchMain\) *****CVS exited normally with code 0*****Step 6: Right click on CVSBranchMain folder and select “Update selection…” option.
Step 7: Make sure “Create missing directories that exist in the repository” is checked.
Step 8: Select the Merge options tab -> Click the Only this rev./tag radio button -> In the Only this rev./tag input field, enter the tag/branch name,”R-0-1-1”. If you want to merge from a given timestamp in this tag, check the Date radio button and type in your preferred timestamp as well. -> Click on OK button.
Step 9: Commit update: Right click on CVSBranchMain à Select Commit selection… -> Enter comment -> click OK.
Posted by
techgeek168
at
10:58 AM
0
comments
Labels: SourceControl



















