/* * public void save(String filename) { * try { * DataOutputStream rf = IOUtils.getDataOutputStream(filename); * save(rf); * rf.close(); * } catch (Exception e) { * e.printStackTrace(); * } * } */ internal virtual void Save(DataOutputStream file) { string[] arr = Sharpen.Collections.ToArray(dict.Keys, new string[dict.Keys.Count]); try { file.WriteInt(arr.Length); log.Info("Saving dictionary of " + arr.Length + " words ..."); foreach (string word in arr) { TagCount count = Get(word); file.WriteUTF(word); count.Save(file); } int[] arrverbs = Sharpen.Collections.ToArray(this.partTakingVerbs.Keys, new int[partTakingVerbs.Keys.Count]); file.WriteInt(arrverbs.Length); foreach (int iO in arrverbs) { CountWrapper tC = this.partTakingVerbs[iO]; file.WriteInt(iO); tC.Save(file); } } catch (Exception e) { Sharpen.Runtime.PrintStackTrace(e); } }
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; } }
public override void ToOutputStream(DataOutputStream writer) { //Server to Client writer.WriteBoolean(DeckImage != null); if (DeckImage != null) { writer.WriteInt(ImageSlot); //Byte array lenght writer.WriteInt(DeckImage.InternalBitmap.Length); writer.Write(DeckImage.InternalBitmap); Json headerContent = new Json(); headerContent.Font = " "; headerContent.Size = CurrentItem.Decksize; headerContent.Position = CurrentItem.Deckposition; headerContent.Text = CurrentItem.Deckname; headerContent.Color = CurrentItem.Deckcolor; headerContent.Stroke_color = CurrentItem.Stroke_color; headerContent.Stroke_dx = CurrentItem.Stroke_dxtext; headerContent.Stroke_radius = CurrentItem.Stroke_radius; headerContent.Stroke_dy = CurrentItem.Stroke_Dy; headerContent.IsStroke = CurrentItem.IsStroke; headerContent.Isboldtext = CurrentItem.Isboldtext; headerContent.Isnormaltext = CurrentItem.Isnormaltext; headerContent.Isitalictext = CurrentItem.Isitalictext; headerContent.Ishinttext = CurrentItem.Ishinttext; string jsonString = JsonConvert.SerializeObject(headerContent, Formatting.None); writer.WriteUTF(jsonString); } }
/// <exception cref="System.IO.IOException"/> private void Save(DataOutputStream @out, string sdPath) { @out.WriteInt(this._enclosing.currentId); this.SaveAllKeys(@out, sdPath); @out.WriteInt(this._enclosing.delegationTokenSequenceNumber); this.SaveCurrentTokens(@out, sdPath); }
/// <summary>Write the word vectors to an output stream.</summary> /// <remarks> /// Write the word vectors to an output stream. The stream is not closed on finishing /// the function. /// </remarks> /// <param name="out">The stream to write to.</param> /// <exception cref="System.IO.IOException">Thrown if the stream could not be written to.</exception> public virtual void Serialize(OutputStream @out) { DataOutputStream dataOut = new DataOutputStream(@out); // Write some length statistics int maxKeyLength = 0; int vectorLength = 0; foreach (KeyValuePair <string, float[]> entry in this) { maxKeyLength = Math.Max(Sharpen.Runtime.GetBytesForString(entry.Key).Length, maxKeyLength); vectorLength = entry.Value.Length; } VectorMap.Itype keyIntType = VectorMap.Itype.GetType(maxKeyLength); // Write the key length dataOut.WriteInt(maxKeyLength); // Write the vector dim dataOut.WriteInt(vectorLength); // Write the size of the dataset dataOut.WriteInt(this.Count); foreach (KeyValuePair <string, float[]> entry_1 in this) { // Write the length of the key byte[] key = Sharpen.Runtime.GetBytesForString(entry_1.Key); keyIntType.Write(dataOut, key.Length); dataOut.Write(key); // Write the vector foreach (float v in entry_1.Value) { dataOut.WriteShort(FromFloat(v)); } } }
public override void ToOutputStream(DataOutputStream writer) { //To client writer.WriteInt(profile.Matriz.Lin); writer.WriteInt(profile.Matriz.Column); }
public byte[] ToByteArray() { MemoryStream byteArrayOutputStream = new MemoryStream(12); DataOutputStream outputStream = new DataOutputStream(byteArrayOutputStream); byte header1 = 0; header1 |= (byte)(Version << 6); header1 |= (byte)((PaddingFlag ? 1 : 0) << 5); header1 |= (byte)((ExtensionFlag ? 1 : 0) << 4); header1 |= ContributingSourceIdentifiersCount; outputStream.WriteByte(header1); byte header2 = 0; header2 |= (byte)((MarkerFlag ? 1 : 0) << 7); header2 |= PayloadType; outputStream.WriteByte(header2); outputStream.WriteShort(SequenceNumber); outputStream.WriteInt(Timestamp); outputStream.WriteInt(Ssrc); outputStream.Flush(); return(byteArrayOutputStream.ToArray()); }
public override void ToOutputStream(DataOutputStream writer) { writer.WriteInt(slotsToSend.Count); foreach (var slot in slotsToSend) { writer.WriteInt(slot); } }
private void SendDeckImage(DataOutputStream writer, int slot, DeckImage img) { if (img != null) { //Write the slot writer.WriteInt(slot); //Write the byte array lenght writer.WriteInt(img.InternalBitmap.Length); //Write the byte array writer.Write(img.InternalBitmap); } }
public override void ToOutputStream(DataOutputStream writer) { //Server to Client writer.WriteBoolean(DeckImage != null); if (DeckImage != null) { writer.WriteInt(ImageSlot); //Byte array lenght writer.WriteInt(DeckImage.InternalBitmap.Length); writer.Write(DeckImage.InternalBitmap); } }
public override void Marshal(DataOutputStream dos) { base.Marshal(dos); if (dos != null) { try { this._entityID.Marshal(dos); dos.WriteUnsignedByte((byte)this._forceId); dos.WriteByte((byte)this._articulationParameters.Count); this._entityType.Marshal(dos); this._alternativeEntityType.Marshal(dos); this._entityLinearVelocity.Marshal(dos); this._entityLocation.Marshal(dos); this._entityOrientation.Marshal(dos); dos.WriteInt((int)this._entityAppearance); this._deadReckoningParameters.Marshal(dos); for (int idx = 0; idx < this._marking.Length; idx++) { dos.WriteByte(this._marking[idx]); } dos.WriteInt((int)this._capabilities); for (int idx = 0; idx < this._articulationParameters.Count; idx++) { ArticulationParameter aArticulationParameter = (ArticulationParameter)this._articulationParameters[idx]; aArticulationParameter.Marshal(dos); } } catch (Exception e) { if (PduBase.TraceExceptions) { Trace.WriteLine(e); Trace.Flush(); } this.RaiseExceptionOccured(e); if (PduBase.ThrowExceptions) { throw e; } } } }
/// <exception cref="System.IO.IOException"/> public static void SaveDoubleArr(DataOutputStream rf, double[] arr) { rf.WriteInt(arr.Length); byte[] lArr = DoubleArrToByteArr(arr); rf.Write(lArr); rf.Close(); }
public override void Marshal(DataOutputStream dos) { base.Marshal(dos); if (dos != null) { try { this._munitionID.Marshal(dos); this._eventID.Marshal(dos); dos.WriteInt((int)this._fireMissionIndex); this._locationInWorldCoordinates.Marshal(dos); this._burstDescriptor.Marshal(dos); this._velocity.Marshal(dos); dos.WriteFloat((float)this._range); } catch (Exception e) { if (PduBase.TraceExceptions) { Trace.WriteLine(e); Trace.Flush(); } this.RaiseExceptionOccured(e); if (PduBase.ThrowExceptions) { throw e; } } } }
/// <exception cref="System.IO.IOException"/> public static void WriteCacheDirectiveInfo(DataOutputStream @out, CacheDirectiveInfo directive) { WriteLong(directive.GetId(), @out); int flags = ((directive.GetPath() != null) ? unchecked ((int)(0x1)) : 0) | ((directive .GetReplication() != null) ? unchecked ((int)(0x2)) : 0) | ((directive.GetPool() != null) ? unchecked ((int)(0x4)) : 0) | ((directive.GetExpiration() != null) ? unchecked ( (int)(0x8)) : 0); @out.WriteInt(flags); if (directive.GetPath() != null) { WriteString(directive.GetPath().ToUri().GetPath(), @out); } if (directive.GetReplication() != null) { WriteShort(directive.GetReplication(), @out); } if (directive.GetPool() != null) { WriteString(directive.GetPool(), @out); } if (directive.GetExpiration() != null) { WriteLong(directive.GetExpiration().GetMillis(), @out); } }
public override void Marshal(DataOutputStream dos) { base.Marshal(dos); if (dos != null) { try { this._originatingSimulationAddress.Marshal(dos); dos.WriteInt((int)this._padding1); dos.WriteShort((short)this._padding2); dos.WriteUnsignedByte((byte)this._attributeRecordPduType); dos.WriteUnsignedByte((byte)this._attributeRecordProtocolVersion); dos.WriteUnsignedInt((uint)this._masterAttributeRecordType); dos.WriteUnsignedByte((byte)this._actionCode); dos.WriteByte((byte)this._padding3); dos.WriteUnsignedShort((ushort)this._numberAttributeRecordSet); } catch (Exception e) { #if DEBUG Trace.WriteLine(e); Trace.Flush(); #endif this.OnException(e); } } }
public virtual void Marshal(DataOutputStream dos) { if (dos != null) { try { dos.WriteInt((int)this._pdus.Count); for (int idx = 0; idx < this._pdus.Count; idx++) { Pdu aPdu = (Pdu)this._pdus[idx]; aPdu.Marshal(dos); } } catch (Exception e) { if (PduBase.TraceExceptions) { Trace.WriteLine(e); Trace.Flush(); } this.RaiseExceptionOccured(e); if (PduBase.ThrowExceptions) { throw e; } } } }
public override void Marshal(DataOutputStream dos) { base.Marshal(dos); if (dos != null) { try { this._entityID.Marshal(dos); dos.WriteByte((byte)this._padding1); dos.WriteUnsignedByte((byte)this._articulationParameters.Count); this._entityLinearVelocity.Marshal(dos); this._entityLocation.Marshal(dos); this._entityOrientation.Marshal(dos); dos.WriteInt((int)this._entityAppearance); for (int idx = 0; idx < this._articulationParameters.Count; idx++) { ArticulationParameter aArticulationParameter = (ArticulationParameter)this._articulationParameters[idx]; aArticulationParameter.Marshal(dos); } } catch (Exception e) { #if DEBUG Trace.WriteLine(e); Trace.Flush(); #endif this.OnException(e); } } }
protected internal virtual void Save(DataOutputStream rf) { try { rf.WriteInt(word.Length); rf.Write(Sharpen.Runtime.GetBytesForString(word)); rf.WriteInt(countPart); rf.WriteInt(countThat); rf.WriteInt(countIn); rf.WriteInt(countRB); } catch (Exception e) { Sharpen.Runtime.PrintStackTrace(e); } }
/// <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(); } }
/// <exception cref="System.IO.IOException"/> public override void StoreToken(TimelineDelegationTokenIdentifier tokenId, long renewDate ) { DataOutputStream ds = null; WriteBatch batch = null; try { byte[] k = CreateTokenEntryKey(tokenId.GetSequenceNumber()); if (db.Get(k) != null) { throw new IOException(tokenId + " already exists"); } byte[] v = BuildTokenData(tokenId, renewDate); ByteArrayOutputStream bs = new ByteArrayOutputStream(); ds = new DataOutputStream(bs); ds.WriteInt(tokenId.GetSequenceNumber()); batch = db.CreateWriteBatch(); batch.Put(k, v); batch.Put(LatestSequenceNumberKey, bs.ToByteArray()); db.Write(batch); } catch (DBException e) { throw new IOException(e); } finally { IOUtils.Cleanup(Log, ds); IOUtils.Cleanup(Log, batch); } }
/// <exception cref="System.IO.IOException"/> public static void SaveFloatArr(DataOutputStream rf, float[] arr) { rf.WriteInt(arr.Length); byte[] lArr = FloatArrToByteArr(arr); rf.Write(lArr); rf.Close(); }
public override void Marshal(DataOutputStream dos) { base.Marshal(dos); if (dos != null) { try { this._munitionID.Marshal(dos); this._eventID.Marshal(dos); dos.WriteInt((int)this._fireMissionIndex); this._locationInWorldCoordinates.Marshal(dos); this._burstDescriptor.Marshal(dos); this._velocity.Marshal(dos); dos.WriteFloat((float)this._range); } catch (Exception e) { #if DEBUG Trace.WriteLine(e); Trace.Flush(); #endif this.OnException(e); } } }
public virtual void Marshal(DataOutputStream dos) { if (dos != null) { try { dos.WriteUnsignedByte((byte)this._parameterTypeDesignator); dos.WriteUnsignedByte((byte)this._changeIndicator); dos.WriteUnsignedShort((ushort)this._partAttachedTo); dos.WriteInt((int)this._parameterType); dos.WriteDouble((double)this._parameterValue); } catch (Exception e) { if (PduBase.TraceExceptions) { Trace.WriteLine(e); Trace.Flush(); } this.RaiseExceptionOccured(e); if (PduBase.ThrowExceptions) { throw e; } } } }
/// <summary>Write an integer of this type to the given output stream</summary> /// <exception cref="System.IO.IOException"/> public void Write(DataOutputStream @out, int value) { switch (this) { case VectorMap.Itype.Int8: { @out.WriteByte(value); break; } case VectorMap.Itype.Int16: { @out.WriteShort(value); break; } case VectorMap.Itype.Int32: { @out.WriteInt(value); break; } default: { throw new Exception("Unknown itype: " + this); } } }
public virtual void Marshal(DataOutputStream dos) { if (dos != null) { try { dos.WriteInt((int)this._hour); dos.WriteUnsignedInt((uint)this._timePastHour); } catch (Exception e) { if (PduBase.TraceExceptions) { Trace.WriteLine(e); Trace.Flush(); } this.RaiseExceptionOccured(e); if (PduBase.ThrowExceptions) { throw e; } } } }
private static void WriteArray <T>(this DataOutputStream stream, T[] array, Action <T> writer) { stream.WriteInt(array.Length); foreach (var value in array) { writer(value); } }
/// <exception cref="System.IO.IOException"/> public virtual void Write(DataOutputStream @out) { System.Diagnostics.Debug.Assert(proto.GetSerializedSize() <= MaxProtoSize, "Expected " + (MaxProtoSize) + " got: " + proto.GetSerializedSize()); @out.WriteInt(packetLen); @out.WriteShort(proto.GetSerializedSize()); proto.WriteTo(@out); }
private void SendDeckLabel(DataOutputStream writer, int slot, DeckItemMisc item) { //Write the slot if (item.GetItemImage() != null) { Json headerContent = new Json(); writer.WriteInt(slot); //Byte array lenght writer.WriteInt(item.GetItemImage().InternalBitmap.Length); writer.Write(item.GetItemImage().InternalBitmap); headerContent.Font = " "; headerContent.Size = item.Decksize; headerContent.Position = item.Deckposition; headerContent.Text = item.Deckname; headerContent.Color = item.Deckcolor; headerContent.Stroke_color = item.Stroke_color; headerContent.Stroke_dx = item.Stroke_dxtext; headerContent.Stroke_radius = item.Stroke_radius; headerContent.Stroke_dy = item.Stroke_Dy; headerContent.IsStroke = item.IsStroke; headerContent.Isboldtext = item.Isboldtext; headerContent.Isnormaltext = item.Isnormaltext; headerContent.Isitalictext = item.Isitalictext; headerContent.Ishinttext = item.Ishinttext; string jsonString = JsonConvert.SerializeObject(headerContent, Formatting.None); writer.WriteUTF(jsonString); ////text //writer.WriteUTF(text); ////size //writer.WriteInt(size); ////position //writer.WriteInt(pos); ////color //writer.WriteUTF(color); } }
public override void ToOutputStream(DataOutputStream writer) { //The number of images to send writer.WriteInt(toSend.Count); foreach (var item in toSend) { SendDeckImage(writer, item.Key, item.Value); } }
/// <exception cref="System.IO.IOException"/> private void WriteZeroLengthPacket(ExtendedBlock block, string description) { PacketHeader hdr = new PacketHeader(8, block.GetNumBytes(), 100, true, 0, false); // size of packet // OffsetInBlock // sequencenumber // lastPacketInBlock // chunk length // sync block hdr.Write(sendOut); sendOut.WriteInt(0); // zero checksum //ok finally write a block with 0 len SendResponse(DataTransferProtos.Status.Success, string.Empty, null, recvOut); new PipelineAck(100, new int[] { PipelineAck.CombineHeader(PipelineAck.ECN.Disabled , DataTransferProtos.Status.Success) }).Write(recvOut); SendRecvData(description, false); }