Example usage for java.io DataOutputStream writeInt

List of usage examples for java.io DataOutputStream writeInt

Introduction

In this page you can find the example usage for java.io DataOutputStream writeInt.

Prototype

public final void writeInt(int v) throws IOException 

Source Link

Document

Writes an int to the underlying output stream as four bytes, high byte first.

Usage

From source file:Version2LicenseDecoder.java

public static String packLicense(byte[] text, byte[] hash) throws LicenseException {
    try {/*w w  w  .ja va 2  s . c o  m*/
        ByteArrayOutputStream e = new ByteArrayOutputStream();
        DataOutputStream dOut = new DataOutputStream(e);
        dOut.writeInt(text.length);
        dOut.write(text);
        dOut.write(hash);
        byte[] allData = e.toByteArray();
        String result = (new String(Base64.encodeBase64(allData))).trim();
        result = result + 'X' + "0" + 2 + Integer.toString(result.length(), 31);
        result = split(result);
        return result;
    } catch (IOException var6) {
        throw new LicenseException(var6);
    }
}

From source file:Version2LicenseDecoder.java

public static String packLicense2(byte[] text, byte[] hash) throws LicenseException {
    try {//  w  ww. java 2  s.  co  m
        ByteArrayOutputStream e = new ByteArrayOutputStream();
        DataOutputStream dOut = new DataOutputStream(e);
        dOut.writeInt(text.length);
        dOut.write(text);
        dOut.write(hash);
        byte[] allData = e.toByteArray();
        String result = (new String(Base64.encodeBase64(allData))).trim();
        result = result + 'X' + "0" + 2 + Integer.toString(result.length(), 31);
        result = split(result);
        return result;
    } catch (IOException var6) {
        throw new LicenseException(var6);
    }
}

From source file:net.timewalker.ffmq4.storage.data.impl.BlockBasedDataStoreTools.java

private static void initAllocationTable(File atFile, int blockCount, int blockSize, boolean forceSync)
        throws DataStoreException {
    log.debug("Creating allocation table (size=" + blockCount + ") ...");

    // Create the file
    try {//from w w  w .ja  v  a 2s. c  o m
        FileOutputStream outFile = new FileOutputStream(atFile);
        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(outFile));

        out.writeInt(blockCount); // Block count
        out.writeInt(blockSize); // Block size
        out.writeInt(-1); // First block index
        for (int n = 0; n < blockCount; n++)
            out.write(EMPTY_BLOCK);
        out.flush();
        if (forceSync)
            outFile.getFD().sync();

        out.close();
    } catch (IOException e) {
        throw new DataStoreException("Cannot initialize allocation table " + atFile.getAbsolutePath(), e);
    }
}

From source file:org.apache.hadoop.hdfs.server.namenode.EditLogFileOutputStream.java

/**
 * Write header information for this EditLogFileOutputStream to the provided
 * DataOutputSream.//from   www .  j  av  a  2  s . c o m
 * 
 * @param layoutVersion the LayoutVersion of the EditLog
 * @param out the output stream to write the header to.
 * @throws IOException in the event of error writing to the stream.
 */
@VisibleForTesting
public static void writeHeader(int layoutVersion, DataOutputStream out) throws IOException {
    out.writeInt(layoutVersion);
    LayoutFlags.write(out);
}

From source file:com.dbay.apns4j.tools.ApnsTools.java

@Deprecated
public final static byte[] generateData(int id, int expire, byte[] token, byte[] payload) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream os = new DataOutputStream(bos);
    try {/*w  w w . j  a  v a 2s  .c om*/
        os.writeByte(Command.SEND);
        os.writeInt(id);
        os.writeInt(expire);
        os.writeShort(token.length);
        os.write(token);
        os.writeShort(payload.length);
        os.write(payload);
        os.flush();
        return bos.toByteArray();
    } catch (IOException e) {
        e.printStackTrace();
    }
    throw new RuntimeException();
}

From source file:com.vimukti.accounter.license.LicenseManager.java

public static String packLicense(byte[] text, byte[] hash) throws LicenseException {
    try {//from   w  ww .  j a  v a  2 s  . c  om
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        DataOutputStream dOut = new DataOutputStream(out);
        dOut.writeInt(text.length);
        dOut.write(text);
        dOut.write(hash);

        byte[] allData = out.toByteArray();
        String result = new String(Base64.encodeBase64(allData)).trim();

        result = result + SEPARATOR + "0" + 1 + Integer.toString(result.length(), ENCODED_LICENSE_LENGTH_BASE);
        result = split(result);
        return result;
    } catch (IOException e) {
        throw new LicenseException(e);
    }

}

From source file:es.logongas.util.seguridad.CodigoVerificacionSeguro.java

private static String createValor(int key) {
    try {/* ww  w . j  a  va  2s  . c o m*/
        //Generar el N aleatorio
        int numeroAleatorio = new Random().nextInt(Integer.MAX_VALUE);
        CRC crc = new CRC();
        crc.update(key).update(numeroAleatorio);

        //Genera el array de datos con el tipo, key y el n aleatorio
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
        dataOutputStream.writeInt(key);
        dataOutputStream.writeInt(numeroAleatorio);
        dataOutputStream.writeInt(crc.getCRC());

        byte[] datos = byteArrayOutputStream.toByteArray();

        //Trasformarlo en un String en Base32
        Base32 base32 = new Base32();
        String codigoVerificacionSeguro = base32.encodeAsString(datos);

        //Quitamos el "=" del final pq no se puedo codificar con el cdigo de barras.
        codigoVerificacionSeguro = codigoVerificacionSeguro.substring(0, codigoVerificacionSeguro.indexOf('='));

        return codigoVerificacionSeguro;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

}

From source file:net.adamcin.httpsig.testutil.KeyTestUtil.java

public static byte[] dumpKeyBlob(PublicKey publicKey) {
    ByteArrayOutputStream byteOs = new ByteArrayOutputStream();

    try {/*w  w  w .j a v a 2 s.  c  o  m*/
        if (publicKey instanceof RSAPublicKey) {
            RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
            DataOutputStream dos = new DataOutputStream(byteOs);
            dos.writeInt("ssh-rsa".getBytes().length);
            dos.write("ssh-rsa".getBytes());
            dos.writeInt(rsaPublicKey.getPublicExponent().toByteArray().length);
            dos.write(rsaPublicKey.getPublicExponent().toByteArray());
            dos.writeInt(rsaPublicKey.getModulus().toByteArray().length);
            dos.write(rsaPublicKey.getModulus().toByteArray());
        } else if (publicKey instanceof DSAPublicKey) {
            DSAPublicKey dsaPublicKey = (DSAPublicKey) publicKey;
            DSAParams dsaParams = dsaPublicKey.getParams();

            DataOutputStream dos = new DataOutputStream(byteOs);
            dos.writeInt("ssh-dss".getBytes().length);
            dos.write("ssh-dss".getBytes());
            dos.writeInt(dsaParams.getP().toByteArray().length);
            dos.write(dsaParams.getP().toByteArray());
            dos.writeInt(dsaParams.getQ().toByteArray().length);
            dos.write(dsaParams.getQ().toByteArray());
            dos.writeInt(dsaParams.getG().toByteArray().length);
            dos.write(dsaParams.getG().toByteArray());
            dos.writeInt(dsaPublicKey.getY().toByteArray().length);
            dos.write(dsaPublicKey.getY().toByteArray());
        } else {
            throw new IllegalArgumentException("Not a supported public key: " + publicKey);
        }
    } catch (IOException e) {
        // shouldn't happen
        LOGGER.error("failed to dump public key blob", e);
    }
    return byteOs.toByteArray();
}

From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java

private static void serializeString(DataOutputStream dos, String string) throws IOException {
    byte[] bytes = string.getBytes();
    dos.writeInt(bytes.length);
    dos.write(bytes);//  ww w.j ava 2 s  .c o  m
}

From source file:org.mobisocial.corral.CorralClient.java

private static String hashToString(long hash) {
    try {/*from   w w w. j  av a  2  s .  c  o  m*/
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(bos);
        dos.writeLong(hash);
        dos.writeInt(-4);
        byte[] data = bos.toByteArray();
        return FastBase64.encodeToString(data).substring(0, 11);
    } catch (IOException e) {
        return null;
    }
}