Skip to content

Commit

Permalink
Factored out steps in reading the SD file data block
Browse files Browse the repository at this point in the history
Signed-off-by: rajarshi <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Oct 1, 2009
1 parent 8c8166a commit 678e7ca
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions src/main/org/openscience/cdk/io/iterator/IteratingMDLReader.java
Expand Up @@ -193,30 +193,9 @@ private void readDataBlockInto(IMolecule m) throws IOException {
logger.debug("looking for data header: ", currentLine);
String str = new String(currentLine);
if (str.startsWith("> ")) {
// ok, should extract the field name
int index = str.indexOf("<");
if (index != -1) {
int index2 = str.substring(index).indexOf(">");
if (index2 != -1) {
fieldName = str.substring(
index+1,
index+index2
);
}
}
// end skip all other lines
while (str.startsWith("> ")) {
logger.debug("data header line: ", currentLine);
currentLine = input.readLine();
str = new String(currentLine);
}
String data = "";
while (str.trim().length() > 0) {
logger.debug("data line: ", currentLine);
data += str;
currentLine = input.readLine();
str = new String(currentLine).trim();
}
fieldName = extractFieldName(fieldName, str);
str = skipOtherFieldHeaderLines(str);
String data = extractFieldData(str);
if (fieldName != null) {
logger.info("fieldName, data: ", fieldName, ", ", data);
m.setProperty(fieldName, data);
Expand All @@ -225,6 +204,40 @@ private void readDataBlockInto(IMolecule m) throws IOException {
currentLine = input.readLine();
}
}

private String extractFieldData(String str) throws IOException {
String data = "";
while (str.trim().length() > 0) {
logger.debug("data line: ", currentLine);
data += str;
currentLine = input.readLine();
str = new String(currentLine).trim();
}
return data;
}

private String skipOtherFieldHeaderLines(String str) throws IOException {
while (str.startsWith("> ")) {
logger.debug("data header line: ", currentLine);
currentLine = input.readLine();
str = new String(currentLine);
}
return str;
}

private String extractFieldName(String fieldName, String str) {
int index = str.indexOf("<");
if (index != -1) {
int index2 = str.substring(index).indexOf(">");
if (index2 != -1) {
fieldName = str.substring(
index+1,
index+index2
);
}
}
return fieldName;
}

/**
* Returns the next IMolecule.
Expand Down

0 comments on commit 678e7ca

Please sign in to comment.