dOut.writeDouble(value);
}
@Override
public void convertString(UTF8StringPointable stringp, DataOutput dOut) throws SystemException, IOException {
ICharacterIterator charIterator = new UTF8StringCharacterIterator(stringp);
charIterator.reset();
short decimalPlace = 0;
long value = 0;
double valueDouble;
boolean pastDecimal = false, negativeValue = false;
int c = ICharacterIterator.EOS_CHAR;
int c2 = ICharacterIterator.EOS_CHAR;
int c3 = ICharacterIterator.EOS_CHAR;
long limit = -Long.MAX_VALUE;
// Check sign.
c = charIterator.next();
if (c == Character.valueOf('-')) {
negativeValue = true;
c = charIterator.next();
limit = Long.MIN_VALUE;
}
// Check the special cases.
if (c == Character.valueOf('I') || c == Character.valueOf('N')) {
c2 = charIterator.next();
c3 = charIterator.next();
if (charIterator.next() != ICharacterIterator.EOS_CHAR) {
throw new SystemException(ErrorCode.FORG0001);
} else if (c == Character.valueOf('I') && c2 == Character.valueOf('N') && c3 == Character.valueOf('F')) {
valueDouble = Double.NEGATIVE_INFINITY;
} else if (c == Character.valueOf('N') && c2 == Character.valueOf('a') && c3 == Character.valueOf('N')) {
valueDouble = Double.NaN;
} else {
throw new SystemException(ErrorCode.FORG0001);
}
} else {
// Read in the number.
do {
if (Character.isDigit(c)) {
if (value < limit / 10 + Character.getNumericValue(c)) {
throw new SystemException(ErrorCode.FOCA0006);
}
value = value * 10 - Character.getNumericValue(c);
if (pastDecimal) {
decimalPlace--;
}
} else if (c == Character.valueOf('.') && pastDecimal == false) {
pastDecimal = true;
} else if (c == Character.valueOf('E') || c == Character.valueOf('e')) {
break;
} else {
throw new SystemException(ErrorCode.FORG0001);
}
} while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR);
// Parse the exponent.
if (c == Character.valueOf('E') || c == Character.valueOf('e')) {
int moveOffset = 0;
boolean negativeOffset = false;
// Check for the negative sign.
c = charIterator.next();
if (c == Character.valueOf('-')) {
negativeOffset = true;
c = charIterator.next();
}
// Process the numeric value.
do {
if (Character.isDigit(c)) {
moveOffset = moveOffset * 10 + Character.getNumericValue(c);
} else {
throw new SystemException(ErrorCode.FORG0001);
}
} while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR);
if (moveOffset > 324 || moveOffset < -324) {
throw new SystemException(ErrorCode.FOCA0006);
}
decimalPlace += (negativeOffset ? -moveOffset : moveOffset);
}