use of java.io.DataOutput in project goldenorb by jzachr.
the class TestOrbPartitionMember method testOrbPartitionMember.
/*
* Start of user / non-generated code -- any code written outside of this block will be
* removed in subsequent code generations.
*/
/* End of user / non-generated code */
@Before
public void testOrbPartitionMember() throws IOException {
/*
* Start of user / non-generated code -- any code written outside of this block will be
* removed in subsequent code generations.
*/
/* End of user / non-generated code */
orbPartitionMember = new OrbPartitionMember();
orbPartitionMember.setPartitionID(INT_PARTITIONID_VALUE);
orbPartitionMember.setNumberOfVertices(INT_NUMBEROFVERTICES_VALUE);
orbPartitionMember.setSuperStep(INT_SUPERSTEP_VALUE);
orbPartitionMember.setMessagesSent(INT_MESSAGESSENT_VALUE);
orbPartitionMember.setPercentComplete(FLOAT_PERCENTCOMPLETE_VALUE);
orbPartitionMember.setHostname(STRING_HOSTNAME_VALUE);
orbPartitionMember.setLeader(BOOLEAN_LEADER_VALUE);
orbPartitionMember.setPort(INT_PORT_VALUE);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutput out = new DataOutputStream(baos);
orbPartitionMember.write(out);
DataInput in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
orbPartitionMemberOut = new OrbPartitionMember();
orbPartitionMemberOut.readFields(in);
/*
* Start of user / non-generated code -- any code written outside of this block will be
* removed in subsequent code generations.
*/
/* End of user / non-generated code */
}
use of java.io.DataOutput in project goldenorb by jzachr.
the class ZookeeperUtils method writableToByteArray.
/**
*
* @param w
* - Writable
* @returns byte[]
*/
public static byte[] writableToByteArray(Writable w) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutput out = new DataOutputStream(baos);
w.write(out);
return baos.toByteArray();
}
use of java.io.DataOutput in project google-authenticator by google.
the class PasscodeGenerator method generateResponseCode.
/**
* @param challenge A long-valued challenge
* @return A decimal response code
* @throws GeneralSecurityException If a JCE exception occur
*/
public String generateResponseCode(long challenge) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
DataOutput dout = new DataOutputStream(out);
try {
dout.writeLong(challenge);
} catch (IOException e) {
// This should never happen with a ByteArrayOutputStream
throw new RuntimeException("Unexpected IOException");
}
byte[] value = out.toByteArray();
return generateResponseCode(value);
}
use of java.io.DataOutput in project asterixdb by apache.
the class AMurmurHash3BinaryHashFunctionFamily method createBinaryHashFunction.
// This hash function family is used to promote a numeric type to a DOUBLE numeric type
// to return same hash value for the original numeric value, regardless of the numeric type.
// (e.g., h( int64("1") ) = h( double("1.0") )
@Override
public IBinaryHashFunction createBinaryHashFunction(final int seed) {
return new IBinaryHashFunction() {
private ArrayBackedValueStorage fieldValueBuffer = new ArrayBackedValueStorage();
private DataOutput fieldValueBufferOutput = fieldValueBuffer.getDataOutput();
private ATypeTag sourceTag = null;
private boolean numericTypePromotionApplied = false;
@Override
public int hash(byte[] bytes, int offset, int length) throws HyracksDataException {
// If a numeric type is encountered, then we promote each numeric type to the DOUBLE type.
fieldValueBuffer.reset();
sourceTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[offset]);
switch(sourceTag) {
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
try {
IntegerToDoubleTypeConvertComputer.getInstance().convertType(bytes, offset + 1, length - 1, fieldValueBufferOutput);
} catch (IOException e) {
throw new HyracksDataException("A numeric type promotion error has occurred before doing hash(). Can't continue process. Detailed Error message:" + e.getMessage());
}
numericTypePromotionApplied = true;
break;
case FLOAT:
try {
FloatToDoubleTypeConvertComputer.getInstance().convertType(bytes, offset + 1, length - 1, fieldValueBufferOutput);
} catch (IOException e) {
throw new HyracksDataException("A numeric type promotion error has occurred before doing hash(). Can't continue process. Detailed Error message:" + e.getMessage());
}
numericTypePromotionApplied = true;
break;
default:
numericTypePromotionApplied = false;
break;
}
// If a numeric type promotion happened
if (numericTypePromotionApplied) {
return MurmurHash3BinaryHash.hash(fieldValueBuffer.getByteArray(), fieldValueBuffer.getStartOffset(), fieldValueBuffer.getLength(), seed);
} else {
// Usual case for non numeric types and the DOBULE numeric type
return MurmurHash3BinaryHash.hash(bytes, offset, length, seed);
}
}
};
}
use of java.io.DataOutput in project asterixdb by apache.
the class IntegerParserFactory method createValueParser.
@Override
public IValueParser createValueParser() {
return new IValueParser() {
@Override
public void parse(char[] buffer, int start, int length, DataOutput out) throws HyracksDataException {
int n = 0;
int sign = 1;
int i = 0;
boolean pre = true;
for (; pre && i < length; ++i) {
char ch = buffer[i + start];
switch(ch) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\f':
break;
case '-':
sign = -1;
pre = false;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
pre = false;
n = n * 10 + (ch - '0');
break;
default:
String errorString = new String(buffer, i + start, length - i);
throw new HyracksDataException("Integer Parser - a digit is expected. But, encountered this character: " + ch + " in the incoming input: " + errorString);
}
}
boolean post = false;
for (; !post && i < length; ++i) {
char ch = buffer[i + start];
switch(ch) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
n = n * 10 + (ch - '0');
break;
default:
String errorString = new String(buffer, i + start, length - i);
throw new HyracksDataException("Integer Parser - a digit is expected. But, encountered this character: " + ch + " in the incoming input: " + errorString);
}
}
for (; i < length; ++i) {
char ch = buffer[i + start];
switch(ch) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\f':
break;
default:
String errorString = new String(buffer, i + start, length - i);
throw new HyracksDataException("Integer Parser - a whitespace, tab, new line, or " + "form-feed expected. But, encountered this character: " + ch + " in the incoming input: " + errorString);
}
}
try {
out.writeInt(n * sign);
} catch (IOException e) {
throw new HyracksDataException(e);
}
}
};
}
Aggregations