Search in sources :

Example 11 with DataOutput

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 */
}
Also used : DataInput(java.io.DataInput) DataOutput(java.io.DataOutput) OrbPartitionMember(org.goldenorb.jet.OrbPartitionMember) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Before(org.junit.Before)

Example 12 with DataOutput

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();
}
Also used : DataOutput(java.io.DataOutput) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 13 with DataOutput

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);
}
Also used : DataOutput(java.io.DataOutput) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 14 with DataOutput

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);
            }
        }
    };
}
Also used : DataOutput(java.io.DataOutput) IBinaryHashFunction(org.apache.hyracks.api.dataflow.value.IBinaryHashFunction) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ATypeTag(org.apache.asterix.om.types.ATypeTag) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 15 with DataOutput

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);
            }
        }
    };
}
Also used : DataOutput(java.io.DataOutput) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

DataOutput (java.io.DataOutput)268 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)140 IPointable (org.apache.hyracks.data.std.api.IPointable)135 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)134 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)133 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)129 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)126 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)125 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)124 IOException (java.io.IOException)117 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)116 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)96 DataOutputStream (java.io.DataOutputStream)56 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)48 Test (org.junit.Test)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)42 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)35 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)33 DataInputStream (java.io.DataInputStream)30 ByteArrayInputStream (java.io.ByteArrayInputStream)29