FileEditor.java revision fb379c70e3fd8a537f311b99be4759ae41e02750
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: FileEditor.java,v 1.2 2008/06/25 05:51:29 qcheng Exp $
*
*/
/**
* Class that provides functionality to match the "lines" with specified
* pattern and remove them from the specified file.
*
*/
public class FileEditor {
}
/**
*
* @param matchPatterns
* a Set of DeletePatterns
* @return true if all the patterns were found and deleted. False if some
* patterns were not found. In such cases no changes are made to
* the file.
* @throws Exception
*/
boolean success = false;
}
return success;
}
boolean success = false;
// found
}
return success;
}
.getPattern());
for (int i = 1; i <= numSuccessiveLines; i++) {
}
}
return removeLines;
}
// Get the line numbers and sort them using TreeSet
+ "will be skipped: " + lineNumbers);
try {
}
} catch (Exception e) {
+ "while removing lines from file. " + getFileName(), e);
throw e;
} finally {
try {
} catch (IOException ie) {
// Ignore
}
}
try {
} catch (IOException ie) {
}
}
}
// Delete the original file and rename temp file as original
}
{
// Determine next line to skip from being written to file
if (!removeLineNumbers.isEmpty()) {
}
} else {
}
return nextLineToRemove;
}
boolean matchFound = false;
// A Map which stores key=value as
// pattern-string=line-number-to-be-removed
try {
}
} catch (Exception e) {
+ "occurred while searching for patterns. ", e);
throw e;
} finally {
try {
} catch (IOException ie) {
// Ignore
}
}
}
return matchedLines;
}
boolean isFound = false;
// Iterate through all active patterns and see if they are present
// in line
+ "pattern " + matchPattern);
// Add the pattern & line number to the Map.
if (!matchPattern.isMatchForLastOccurranceInFile()) {
// We don't want this match to be active anymore as the
// first occurance is already found.
matchPattern.setIsActiveFlag(false);
}
isFound = true;
}
}
}
}
}
private String getTempFileName() {
return getFileName() + STR_TEMP_FILE_SUFFIX;
}
private String getFileName() {
return fileName;
}
}
}