List of usage examples for java.io DataOutputStream writeLong
public final void writeLong(long v) throws IOException
long
to the underlying output stream as eight bytes, high byte first. From source file:com.codefollower.lealone.omid.tso.TSOHandler.java
private void handleHalfAbort(long startTimestamp) { abortCounter.incrementAndGet();//w w w. j a v a 2 s . com synchronized (sharedState) { DataOutputStream toWAL = sharedState.toWAL; try { toWAL.writeByte(LoggerProtocol.ABORT); toWAL.writeLong(startTimestamp); } catch (IOException e) { LOG.error("failed to write abort wal", e); } sharedState.processHalfAbort(startTimestamp); synchronized (sharedMsgBufLock) { queueHalfAbort(startTimestamp); } } }
From source file:com.codefollower.lealone.omid.tso.TSOHandler.java
/** * Handle the FullAbortReport message//from w w w . ja v a2s . c o m */ private void handle(FullAbortRequest msg, ChannelHandlerContext ctx) { synchronized (sharedState) { DataOutputStream toWAL = sharedState.toWAL; try { toWAL.writeByte(LoggerProtocol.FULL_ABORT); toWAL.writeLong(msg.startTimestamp); } catch (IOException e) { LOG.error("failed to write fullabort wal", e); } sharedState.processFullAbort(msg.startTimestamp); } synchronized (sharedMsgBufLock) { queueFullAbort(msg.startTimestamp); } }
From source file:org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager.java
/** * Private helper methods to save delegation keys and tokens in fsimage *//*w w w .j av a 2 s .c o m*/ private synchronized void saveCurrentTokens(DataOutputStream out) throws IOException { out.writeInt(currentTokens.size()); Iterator<DelegationTokenIdentifier> iter = currentTokens.keySet().iterator(); while (iter.hasNext()) { DelegationTokenIdentifier id = iter.next(); id.write(out); DelegationTokenInformation info = currentTokens.get(id); out.writeLong(info.getRenewDate()); } }
From source file:org.apache.jackrabbit.core.journal.FileRecordLog.java
/** * Initialize this record log by writing a header containing the * previous revision./*from w w w. java 2 s. c om*/ */ public void init(long previousRevision) throws IOException { if (isNew) { DataOutputStream out = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(logFile), 128)); try { writeHeader(out); out.writeLong(previousRevision); } finally { close(out); } this.previousRevision = previousRevision; this.lastRevision = previousRevision; isNew = false; } }
From source file:de.hybris.platform.cuppytrail.impl.DefaultSecureTokenService.java
@Override public String encryptData(final SecureToken data) { if (data == null || StringUtils.isBlank(data.getData())) { throw new IllegalArgumentException("missing token"); }/*from w ww. j av a2 s . co m*/ try { final SecureRandom random = SecureRandom.getInstance(RANDOM_ALGORITHM); final int[] paddingSizes = computePaddingLengths(random); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); dataOutputStream.write(generatePadding(paddingSizes[0], random)); dataOutputStream.writeUTF(data.getData()); dataOutputStream.writeUTF(createChecksum(data.getData())); dataOutputStream.writeLong(data.getTimeStamp()); dataOutputStream.write(generatePadding(paddingSizes[1], random)); dataOutputStream.flush(); final byte[] unsignedDataBytes = byteArrayOutputStream.toByteArray(); final byte[] md5SigBytes = generateSignature(unsignedDataBytes, 0, unsignedDataBytes.length, signatureKeyBytes); byteArrayOutputStream.write(md5SigBytes); byteArrayOutputStream.flush(); final byte[] signedDataBytes = byteArrayOutputStream.toByteArray(); return encrypt(signedDataBytes, encryptionKeyBytes, random); } catch (final IOException e) { LOG.error("Could not encrypt", e); throw new SystemException(e.toString(), e); } catch (final GeneralSecurityException e) { LOG.error("Could not encrypt", e); throw new SystemException(e.toString(), e); } }
From source file:com.linkedin.pinot.core.segment.creator.impl.SegmentIndexCreationDriverImpl.java
/** * Writes segment creation metadata to disk. *///from w w w. j a v a 2s.c om void persistCreationMeta(File outputDir, long crc) throws IOException { final File crcFile = new File(outputDir, V1Constants.SEGMENT_CREATION_META); final DataOutputStream out = new DataOutputStream(new FileOutputStream(crcFile)); out.writeLong(crc); long creationTime = System.currentTimeMillis(); // Use the creation time from the configuration if it exists and is not -1 try { long configCreationTime = Long.parseLong(config.getCreationTime()); if (0L < configCreationTime) { creationTime = configCreationTime; } } catch (Exception nfe) { // Ignore NPE and NFE, use the current time. } out.writeLong(creationTime); out.close(); }
From source file:ubic.basecode.io.ByteArrayConverter.java
/** * @param larray//from w w w . j av a 2s . c o m * @return byte[] */ public byte[] longArrayToBytes(long[] larray) { if (larray == null) return null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); try { for (long element : larray) { dos.writeLong(element); } dos.close(); bos.close(); } catch (IOException e) { // do nothing } return bos.toByteArray(); }
From source file:org.hydracache.server.data.versioning.VectorClockVersionFactory.java
@Override public void writeObject(final Version version, final DataOutputStream dataOut) throws IOException { Validate.isTrue(version instanceof VectorClock, "version must be non null and an instance of VectorClock"); Validate.notNull(dataOut, "dataOut can not be null"); final VectorClock vectorClock = (VectorClock) version; final List<VectorClockEntry> vectorClockEntries = vectorClock.getEntries(); dataOut.writeInt(vectorClockEntries.size()); for (final VectorClockEntry vce : vectorClockEntries) { getIdentityMarshaller().writeObject(vce.getNodeId(), dataOut); dataOut.writeLong(vce.getValue()); dataOut.writeLong(vce.getTimestamp()); }//from w w w. ja v a 2 s . co m }
From source file:org.slc.sli.dal.encrypt.AesCipher.java
@Override public String encrypt(Object data) { if (data instanceof String) { return "ESTRING:" + encryptFromBytes(StringUtils.getBytesUtf8((String) data)); } else {// w w w. ja v a 2 s . com ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(byteOutputStream); String type; try { if (data instanceof Boolean) { dos.writeBoolean((Boolean) data); type = "EBOOL:"; } else if (data instanceof Integer) { dos.writeInt((Integer) data); type = "EINT:"; } else if (data instanceof Long) { dos.writeLong((Long) data); type = "ELONG:"; } else if (data instanceof Double) { dos.writeDouble((Double) data); type = "EDOUBLE:"; } else { throw new RuntimeException("Unsupported type: " + data.getClass().getCanonicalName()); } dos.flush(); dos.close(); } catch (IOException e) { throw new RuntimeException(e); } byte[] bytes = byteOutputStream.toByteArray(); return type + encryptFromBytes(bytes); } }
From source file:com.yahoo.omid.tso.TSOHandler.java
public void handle(AbortRequest msg, ChannelHandlerContext ctx) { synchronized (sharedState) { DataOutputStream toWAL = sharedState.toWAL; try {//from ww w . ja v a2 s . c om toWAL.writeByte(LoggerProtocol.ABORT); toWAL.writeLong(msg.startTimestamp); } catch (IOException e) { e.printStackTrace(); } abortCount++; sharedState.processAbort(msg.startTimestamp); synchronized (sharedMsgBufLock) { queueHalfAbort(msg.startTimestamp); } } }