small ADMParser/AdmLexer cleanup
- do not declare IOExceptions that are not thrown
- improve formatting of lexer template
Change-Id: Id032f0c83ebef108a9eddb7242c586d5481217e4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1032
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
index 58d7c83..eb81d3f 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
@@ -124,11 +124,11 @@
}
}
- public ADMDataParser(ARecordType recordType, boolean isStream) throws IOException {
+ public ADMDataParser(ARecordType recordType, boolean isStream) {
this(null, recordType, isStream);
}
- public ADMDataParser(String filename, ARecordType recordType, boolean isStream) throws IOException {
+ public ADMDataParser(String filename, ARecordType recordType, boolean isStream) {
this.filename = filename;
this.recordType = recordType;
this.isStreamParser = isStream;
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/ADMDataParserFactory.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/ADMDataParserFactory.java
index 7732820..efc9574 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/ADMDataParserFactory.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/factory/ADMDataParserFactory.java
@@ -18,9 +18,9 @@
*/
package org.apache.asterix.external.parser.factory;
-import org.apache.asterix.external.api.IExternalDataSourceFactory.DataSourceType;
import org.apache.asterix.external.api.IRecordDataParser;
import org.apache.asterix.external.api.IStreamDataParser;
+import org.apache.asterix.external.api.IExternalDataSourceFactory.DataSourceType;
import org.apache.asterix.external.parser.ADMDataParser;
import org.apache.asterix.external.util.ExternalDataUtils;
import org.apache.asterix.om.types.ARecordType;
@@ -32,18 +32,13 @@
private static final long serialVersionUID = 1L;
@Override
- public IRecordDataParser<char[]> createRecordParser(IHyracksTaskContext ctx) throws HyracksDataException {
+ public IRecordDataParser<char[]> createRecordParser(IHyracksTaskContext ctx) {
return createParser();
}
- private ADMDataParser createParser() throws HyracksDataException {
- try {
- ADMDataParser parser = new ADMDataParser(recordType,
- ExternalDataUtils.getDataSourceType(configuration).equals(DataSourceType.STREAM));
- return parser;
- } catch (Exception e) {
- throw new HyracksDataException(e);
- }
+ private ADMDataParser createParser() {
+ return new ADMDataParser(recordType,
+ ExternalDataUtils.getDataSourceType(configuration).equals(DataSourceType.STREAM));
}
@Override
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/adapter/TestTypedAdapterFactory.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/adapter/TestTypedAdapterFactory.java
index 6850c2b..d45097a 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/adapter/TestTypedAdapterFactory.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/library/adapter/TestTypedAdapterFactory.java
@@ -83,18 +83,12 @@
.getApplicationObject();
ClusterPartition nodePartition = propertiesProvider.getMetadataProperties().getNodePartitions()
.get(nodeId)[0];
- try {
- parser = new ADMDataParser(outputType, true);
- forwarder = DataflowUtils
- .getTupleForwarder(configuration,
- FeedUtils.getFeedLogManager(ctx,
- FeedUtils.splitsForAdapter(ExternalDataUtils.getDataverse(configuration),
- ExternalDataUtils.getFeedName(configuration), nodeId,
- nodePartition)));
- tb = new ArrayTupleBuilder(1);
- } catch (Exception e) {
- throw new HyracksDataException(e);
- }
+ parser = new ADMDataParser(outputType, true);
+ forwarder = DataflowUtils.getTupleForwarder(configuration,
+ FeedUtils.getFeedLogManager(ctx,
+ FeedUtils.splitsForAdapter(ExternalDataUtils.getDataverse(configuration),
+ ExternalDataUtils.getFeedName(configuration), nodeId, nodePartition)));
+ tb = new ArrayTupleBuilder(1);
return new ITupleParser() {
@Override
diff --git a/asterixdb/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java b/asterixdb/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
index 495a95e..3613166 100644
--- a/asterixdb/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
+++ b/asterixdb/asterix-maven-plugins/lexer-generator-maven-plugin/src/main/resources/Lexer.java
@@ -73,22 +73,22 @@
// Public interface
// ================================================================================
- public [LEXER_NAME](java.io.Reader stream) throws IOException{
+ public [LEXER_NAME](java.io.Reader stream) throws IOException {
reInit(stream);
}
- public [LEXER_NAME]() throws IOException{
+ public [LEXER_NAME]() {
reInit();
}
- public void setBuffer(char[] buffer){
+ public void setBuffer(char[] buffer) {
this.buffer = buffer;
tokenBegin = bufpos = 0;
containsEscapes = false;
tokenBegin = -1;
}
- public void reInit(){
+ public void reInit() {
bufsize = Integer.MAX_VALUE;
endOf_UNUSED_Buffer = bufsize;
endOf_USED_Buffer = bufsize;
@@ -99,7 +99,7 @@
maxUnusedBufferSize = bufsize;
}
- public void reInit(java.io.Reader stream) throws IOException{
+ public void reInit(java.io.Reader stream) throws IOException {
done();
inputStream = stream;
bufsize = 4096;
@@ -117,11 +117,11 @@
}
public String getLastTokenImage() {
- if (bufpos >= tokenBegin)
+ if (bufpos >= tokenBegin) {
return new String(buffer, tokenBegin, bufpos - tokenBegin);
- else
- return new String(buffer, tokenBegin, bufsize - tokenBegin) +
- new String(buffer, 0, bufpos);
+ } else {
+ return new String(buffer, tokenBegin, bufsize - tokenBegin) + new String(buffer, 0, bufpos);
+ }
}
public int getColumn() {
@@ -163,27 +163,21 @@
protected void updateLineColumn(char c){
column++;
- if (prevCharIsLF)
- {
+ if (prevCharIsLF) {
prevCharIsLF = false;
line += (column = 1);
- }
- else if (prevCharIsCR)
- {
+ } else if (prevCharIsCR) {
prevCharIsCR = false;
- if (c == '\n')
- {
+ if (c == '\n') {
prevCharIsLF = true;
- }
- else
- {
+ } else {
line += (column = 1);
}
}
if (c=='\r') {
prevCharIsCR = true;
- } else if(c == '\n') {
+ } else if (c == '\n') {
prevCharIsLF = true;
}
}
@@ -193,73 +187,79 @@
// ================================================================================
protected char readNextChar() throws IOException {
- if (++bufpos >= endOf_USED_Buffer)
+ if (++bufpos >= endOf_USED_Buffer) {
fillBuff();
+ }
char c = buffer[bufpos];
updateLineColumn(c);
return c;
}
protected boolean fillBuff() throws IOException {
- if (endOf_UNUSED_Buffer == endOf_USED_Buffer) // If no more unused buffer space
- {
- if (endOf_UNUSED_Buffer == bufsize) // -- If the previous unused space was
- { // -- at the end of the buffer
- if (tokenBegin > maxUnusedBufferSize) // -- -- If the first N bytes before
- { // the current token are enough
- bufpos = endOf_USED_Buffer = 0; // -- -- -- setup buffer to use that fragment
- endOf_UNUSED_Buffer = tokenBegin;
+ if (endOf_UNUSED_Buffer == endOf_USED_Buffer) {
+ // If no more unused buffer space
+ if (endOf_UNUSED_Buffer == bufsize) {
+ // If the previous unused space was at the end of the buffer
+ if (tokenBegin > maxUnusedBufferSize) {
+ // If the first N bytes before the current token are enough
+ // setup buffer to use that fragment
+ bufpos = endOf_USED_Buffer = 0;
+ endOf_UNUSED_Buffer = tokenBegin;
+ } else if (tokenBegin < 0){
+ // If no token yet
+ // reuse the whole buffer
+ bufpos = endOf_USED_Buffer = 0;
+ } else {
+ // Otherwise expand buffer after its end
+ ExpandBuff(false);
+ }
+ } else if (endOf_UNUSED_Buffer > tokenBegin){
+ // If the endOf_UNUSED_Buffer is after the token
+ // set endOf_UNUSED_Buffer to the end of the buffer
+ endOf_UNUSED_Buffer = bufsize;
+ } else if ((tokenBegin - endOf_UNUSED_Buffer) < maxUnusedBufferSize) {
+ // If between endOf_UNUSED_Buffer and the token there is NOT enough space expand the buffer
+ // reorganizing it
+ ExpandBuff(true);
+ } else {
+ // Otherwise there is enough space at the start
+ // so we set the buffer to use that fragment
+ endOf_UNUSED_Buffer = tokenBegin;
}
- else if (tokenBegin < 0) // -- -- If no token yet
- bufpos = endOf_USED_Buffer = 0; // -- -- -- reuse the whole buffer
- else
- ExpandBuff(false); // -- -- Otherwise expand buffer after its end
- }
- else if (endOf_UNUSED_Buffer > tokenBegin) // If the endOf_UNUSED_Buffer is after the token
- endOf_UNUSED_Buffer = bufsize; // -- set endOf_UNUSED_Buffer to the end of the buffer
- else if ((tokenBegin - endOf_UNUSED_Buffer) < maxUnusedBufferSize)
- { // If between endOf_UNUSED_Buffer and the token
- ExpandBuff(true); // there is NOT enough space expand the buffer
- } // reorganizing it
- else
- endOf_UNUSED_Buffer = tokenBegin; // Otherwise there is enough space at the start
- } // so we set the buffer to use that fragment
+ }
int i;
- if ((i = inputStream.read(buffer, endOf_USED_Buffer, endOf_UNUSED_Buffer - endOf_USED_Buffer)) == -1)
- {
+ if ((i = inputStream.read(buffer, endOf_USED_Buffer, endOf_UNUSED_Buffer - endOf_USED_Buffer)) == -1) {
inputStream.close();
- buffer[endOf_USED_Buffer]=(char)EOF_CHAR;
+ buffer[endOf_USED_Buffer] = (char)EOF_CHAR;
endOf_USED_Buffer++;
return false;
+ } else {
+ endOf_USED_Buffer += i;
}
- else
- endOf_USED_Buffer += i;
return true;
}
- protected void ExpandBuff(boolean wrapAround)
- {
- char[] newbuffer = new char[bufsize + maxUnusedBufferSize];
+ protected void ExpandBuff(boolean wrapAround) {
+ char[] newbuffer = new char[bufsize + maxUnusedBufferSize];
- try {
- if (wrapAround) {
- System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
- System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
- buffer = newbuffer;
- endOf_USED_Buffer = (bufpos += (bufsize - tokenBegin));
+ try {
+ if (wrapAround) {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
+ buffer = newbuffer;
+ endOf_USED_Buffer = (bufpos += (bufsize - tokenBegin));
+ } else {
+ System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
+ buffer = newbuffer;
+ endOf_USED_Buffer = (bufpos -= tokenBegin);
+ }
+ } catch (Throwable t) {
+ throw new Error(t.getMessage());
}
- else {
- System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
- buffer = newbuffer;
- endOf_USED_Buffer = (bufpos -= tokenBegin);
- }
- } catch (Throwable t) {
- throw new Error(t.getMessage());
- }
- bufsize += maxUnusedBufferSize;
- endOf_UNUSED_Buffer = bufsize;
- tokenBegin = 0;
+ bufsize += maxUnusedBufferSize;
+ endOf_UNUSED_Buffer = bufsize;
+ tokenBegin = 0;
}
}