public int write(DataOutputStream dos) { int size = 5; dos.WriteUTF(Streamable.MESSAGE_IONO); // 5 dos.WriteInt(STREAM_V); size += 4; dos.WriteLong(health); size += 8; dos.WriteDouble(utcA1); size += 8; dos.WriteDouble(utcA0); size += 8; dos.WriteLong(utcTOW); size += 8; dos.WriteInt(utcWNT); size += 4; dos.WriteInt(utcLS); size += 4; dos.WriteInt(utcWNF); size += 4; dos.WriteInt(utcDN); size += 4; dos.WriteInt(utcLSF); size += 4; for (int i = 0; i < alpha.Count(); i++) { dos.WriteFloat(alpha[i]); size += 4; } for (int i = 0; i < beta.Count(); i++) { dos.WriteFloat(beta[i]); size += 4; } dos.WriteBoolean(validHealth); size += 1; dos.WriteBoolean(validUTC); size += 1; dos.WriteBoolean(validKlobuchar); size += 1; dos.WriteLong(refTime == null ? -1 : refTime.getMsec()); size += 8; return(size); }
private void WriteToDisk(System.IO.IsolatedStorage.IsolatedStorageFile iso, string storeFile) { DataOutputStream dos = FileUtils.WriteIsolatedStorageFileToDataInput(iso, storeFile); try { dos.WriteUTF(HEADER); dos.WriteInt(nextRecordId); dos.WriteInt(records.Count); for (int i = 0; i < records.Count; i++) { RecordItem ri = records[i]; long pSize = ri.data.Length; int pId = ri.id; dos.WriteLong(pSize); dos.WriteInt(pId); dos.Write(ri.data); } } catch (Exception e) { throw new RecordStoreException("Error writing store to disk: " + e.StackTrace); } finally { if (dos != null) { dos.Close(); } dos = null; } }
/// <exception cref="System.IO.IOException"/> public override void StoreToken(MRDelegationTokenIdentifier tokenId, long renewDate ) { if (Log.IsDebugEnabled()) { Log.Debug("Storing token " + tokenId.GetSequenceNumber()); } ByteArrayOutputStream memStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(memStream); try { tokenId.Write(dataStream); dataStream.WriteLong(renewDate); dataStream.Close(); dataStream = null; } finally { IOUtils.Cleanup(Log, dataStream); } string dbKey = GetTokenDatabaseKey(tokenId); try { db.Put(JniDBFactory.Bytes(dbKey), memStream.ToByteArray()); } catch (DBException e) { throw new IOException(e); } }
// Helper function that writes an INodeUnderConstruction // into the output stream // /// <exception cref="System.IO.IOException"/> internal static void WriteINodeUnderConstruction(DataOutputStream @out, INodeFile cons, string path) { WriteString(path, @out); @out.WriteLong(cons.GetId()); @out.WriteShort(cons.GetFileReplication()); @out.WriteLong(cons.GetModificationTime()); @out.WriteLong(cons.GetPreferredBlockSize()); WriteBlocks(cons.GetBlocks(), @out); cons.GetPermissionStatus().Write(@out); FileUnderConstructionFeature uc = cons.GetFileUnderConstructionFeature(); WriteString(uc.GetClientName(), @out); WriteString(uc.GetClientMachine(), @out); @out.WriteInt(0); }
/// <exception cref="System.Exception"/> private void AddOrUpdateToken(TokenIdent ident, AbstractDelegationTokenSecretManager.DelegationTokenInformation info, bool isUpdate) { string nodeCreatePath = GetNodePath(ZkDtsmTokensRoot, DelegationTokenPrefix + ident .GetSequenceNumber()); ByteArrayOutputStream tokenOs = new ByteArrayOutputStream(); DataOutputStream tokenOut = new DataOutputStream(tokenOs); ByteArrayOutputStream seqOs = new ByteArrayOutputStream(); try { ident.Write(tokenOut); tokenOut.WriteLong(info.GetRenewDate()); tokenOut.WriteInt(info.GetPassword().Length); tokenOut.Write(info.GetPassword()); if (Log.IsDebugEnabled()) { Log.Debug((isUpdate ? "Updating " : "Storing ") + "ZKDTSMDelegationToken_" + ident .GetSequenceNumber()); } if (isUpdate) { zkClient.SetData().ForPath(nodeCreatePath, tokenOs.ToByteArray()).SetVersion(-1); } else { zkClient.Create().WithMode(CreateMode.Persistent).ForPath(nodeCreatePath, tokenOs .ToByteArray()); } } finally { seqOs.Close(); } }
public byte[] ToByteArray() { MemoryStream outputStream = new MemoryStream(); DataOutputStream dataOutputStream = new DataOutputStream(outputStream); dataOutputStream.Write(MIDI_COMMAND_HEADER1); dataOutputStream.Write(MIDI_COMMAND_HEADER2); dataOutputStream.Write(System.Text.Encoding.UTF8.GetBytes(CommandWord.ToString())); dataOutputStream.WriteInt(Ssrc); dataOutputStream.WriteByte(Count); dataOutputStream.Write(new byte[3]); dataOutputStream.WriteLong(Timestamp1); dataOutputStream.WriteLong(Timestamp2); dataOutputStream.WriteLong(Timestamp3); dataOutputStream.Flush(); return(outputStream.ToArray()); }
/* (non-Javadoc) * @see org.gogpsproject.Streamable#write(java.io.DataOutputStream) */ public int write(DataOutputStream dos) { int size = 5; dos.WriteUTF(Streamable.MESSAGE_EPHEMERIS); // 5 dos.WriteInt(STREAM_V); size += 4; // 4 dos.WriteLong(refTime == null?-1:refTime.getMsec()); size += 8; dos.Write(satID); size += 1; dos.WriteInt(week); size += 4; dos.WriteInt(L2Code); size += 4; dos.WriteInt(L2Flag); size += 4; dos.WriteInt(svAccur); size += 4; dos.WriteInt(svHealth); size += 4; dos.WriteInt(iode); size += 4; dos.WriteInt(iodc); size += 4; dos.WriteDouble(toc); size += 8; dos.WriteDouble(toe); size += 8; dos.WriteDouble(af0); size += 8; dos.WriteDouble(af1); size += 8; dos.WriteDouble(af2); size += 8; dos.WriteDouble(tgd); size += 8; dos.WriteDouble(rootA); size += 8; dos.WriteDouble(e); size += 8; dos.WriteDouble(i0); size += 8; dos.WriteDouble(iDot); size += 8; dos.WriteDouble(omega); size += 8; dos.WriteDouble(omega0); size += 8; dos.WriteDouble(omegaDot); size += 8; dos.WriteDouble(M0); size += 8; dos.WriteDouble(deltaN); size += 8; dos.WriteDouble(crc); size += 8; dos.WriteDouble(crs); size += 8; dos.WriteDouble(cuc); size += 8; dos.WriteDouble(cus); size += 8; dos.WriteDouble(cic); size += 8; dos.WriteDouble(cis); size += 8; dos.WriteDouble(fitInt); size += 8; return(size); }
/// <exception cref="System.IO.IOException"/> private static void WriteFile(FileSystem fs, Path f, long fill, int parts) { FSDataOutputStream @out = fs.Create(f, false); CheckedOutputStream iout = new CheckedOutputStream(@out, new CRC32()); DataOutputStream dout = new DataOutputStream(iout); for (int i = 0; i < parts; ++i) { for (int j = 0; j < MapTask.MapOutputIndexRecordLength / 8; ++j) { dout.WriteLong(fill); } } @out.WriteLong(iout.GetChecksum().GetValue()); dout.Close(); }
/// <summary>Write an array of blocks as compactly as possible.</summary> /// <remarks> /// Write an array of blocks as compactly as possible. This uses /// delta-encoding for the generation stamp and size, following /// the principle that genstamp increases relatively slowly, /// and size is equal for all but the last block of a file. /// </remarks> /// <exception cref="System.IO.IOException"/> public static void WriteCompactBlockArray(Block[] blocks, DataOutputStream @out) { WritableUtils.WriteVInt(@out, blocks.Length); Block prev = null; foreach (Block b in blocks) { long szDelta = b.GetNumBytes() - (prev != null ? prev.GetNumBytes() : 0); long gsDelta = b.GetGenerationStamp() - (prev != null ? prev.GetGenerationStamp() : 0); @out.WriteLong(b.GetBlockId()); // blockid is random WritableUtils.WriteVLong(@out, szDelta); WritableUtils.WriteVLong(@out, gsDelta); prev = b; } }
public override void Marshal(DataOutputStream dos) { base.Marshal(dos); if (dos != null) { try { this._environmentalSimulationApplicationID.Marshal(dos); dos.WriteUnsignedShort((ushort)this._fieldNumber); dos.WriteUnsignedShort((ushort)this._pduNumber); dos.WriteUnsignedShort((ushort)this._pduTotal); dos.WriteUnsignedShort((ushort)this._coordinateSystem); dos.WriteUnsignedByte((byte)this._gridDataList.Count); dos.WriteUnsignedByte((byte)this._constantGrid); this._environmentType.Marshal(dos); this._orientation.Marshal(dos); dos.WriteLong((long)this._sampleTime); dos.WriteUnsignedInt((uint)this._totalValues); dos.WriteUnsignedByte((byte)this._vectorDimension); dos.WriteUnsignedShort((ushort)this._padding1); dos.WriteUnsignedByte((byte)this._padding2); for (int idx = 0; idx < this._gridDataList.Count; idx++) { GridAxisRecord aGridAxisRecord = (GridAxisRecord)this._gridDataList[idx]; aGridAxisRecord.Marshal(dos); } } catch (Exception e) { if (PduBase.TraceExceptions) { Trace.WriteLine(e); Trace.Flush(); } this.RaiseExceptionOccured(e); if (PduBase.ThrowExceptions) { throw e; } } } }
public virtual void Marshal(DataOutputStream dos) { if (dos != null) { try { this._expendableType.Marshal(dos); dos.WriteLong((long)this._padding); } catch (Exception e) { #if DEBUG Trace.WriteLine(e); Trace.Flush(); #endif this.OnException(e); } } }
/// <exception cref="System.IO.IOException"/> private byte[] BuildTokenData(MRDelegationTokenIdentifier tokenId, long renewDate ) { ByteArrayOutputStream memStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(memStream); try { tokenId.Write(dataStream); dataStream.WriteLong(renewDate); dataStream.Close(); dataStream = null; } finally { IOUtils.Cleanup(Log, dataStream); } return(memStream.ToByteArray()); }
/// <exception cref="System.Exception"/> public virtual void TestBadIndex() { int parts = 30; fs.Delete(p, true); conf.SetInt(TTConfig.TtIndexCache, 1); IndexCache cache = new IndexCache(conf); Path f = new Path(p, "badindex"); FSDataOutputStream @out = fs.Create(f, false); CheckedOutputStream iout = new CheckedOutputStream(@out, new CRC32()); DataOutputStream dout = new DataOutputStream(iout); for (int i = 0; i < parts; ++i) { for (int j = 0; j < MapTask.MapOutputIndexRecordLength / 8; ++j) { if (0 == (i % 3)) { dout.WriteLong(i); } else { @out.WriteLong(i); } } } @out.WriteLong(iout.GetChecksum().GetValue()); dout.Close(); try { cache.GetIndexInformation("badindex", 7, f, UserGroupInformation.GetCurrentUser() .GetShortUserName()); Fail("Did not detect bad checksum"); } catch (IOException e) { if (!(e.InnerException is ChecksumException)) { throw; } } }
/// <summary>Private helper methods to save delegation keys and tokens in fsimage</summary> /// <exception cref="System.IO.IOException"/> private void SaveCurrentTokens(DataOutputStream @out, string sdPath) { lock (this) { StartupProgress prog = NameNode.GetStartupProgress(); Step step = new Step(StepType.DelegationTokens, sdPath); prog.BeginStep(Phase.SavingCheckpoint, step); prog.SetTotal(Phase.SavingCheckpoint, step, this._enclosing.currentTokens.Count); StartupProgress.Counter counter = prog.GetCounter(Phase.SavingCheckpoint, step); @out.WriteInt(this._enclosing.currentTokens.Count); IEnumerator <DelegationTokenIdentifier> iter = this._enclosing.currentTokens.Keys. GetEnumerator(); while (iter.HasNext()) { DelegationTokenIdentifier id = iter.Next(); id.Write(@out); AbstractDelegationTokenSecretManager.DelegationTokenInformation info = this._enclosing .currentTokens[id]; @out.WriteLong(info.GetRenewDate()); counter.Increment(); } prog.EndStep(Phase.SavingCheckpoint, step); } }