public virtual void writeCompressed(ExtendedDataOutput output) { int dataType = (int)this.getDataType(); int unitLength = getUnitLength(this.getDataType()); int elementCount = this.rows(); int maxCompressedLength = this.rows() * sizeof(long) * 8 * 2 + 64 * 3; ByteBuffer outBuffer = ByteBuffer.Allocate(Math.Max(maxCompressedLength, 65536)); outBuffer.order(output.GetType() == typeof(LittleEndianDataOutputStream)); short flag = (short)((short)DATA_FORM.DF_VECTOR << 8 | (short)DATA_TYPE.DT_COMPRESS & 0xff); outBuffer.WriteShort(flag); outBuffer.WriteInt(0); // compressedBytes outBuffer.WriteInt(1); // cols outBuffer.WriteByte((byte)0); // version outBuffer.WriteByte((byte)1); // flag bit0:littleEndian bit1:containChecksum outBuffer.WriteByte(unchecked ((byte)-1)); // charcode outBuffer.WriteByte((byte)compressedMethod); outBuffer.WriteByte((byte)dataType); outBuffer.WriteByte((byte)unitLength); outBuffer.WriteByte((byte)0); outBuffer.WriteByte((byte)0); outBuffer.WriteInt(-1); //extra outBuffer.WriteInt(elementCount); outBuffer.WriteInt(-1); //TODO: checkSum EncoderFactory.Get(compressedMethod).compress(this, elementCount, unitLength, maxCompressedLength, outBuffer); int compressedLength = outBuffer.ReadableBytes - 10; outBuffer.PutInt(compressedLength, 2); byte[] tmp = new byte[outBuffer.ReadableBytes]; output.write(outBuffer.ToArray()); }
public virtual void write(ExtendedDataOutput @out) { if (valueType == DATA_TYPE.DT_DICTIONARY) { throw new IOException("Can't streamlize the dictionary with value type " + valueType.ToString()); } BasicEntityFactory factory = new BasicEntityFactory(); IVector keys = (IVector)factory.createScalarWithDefaultValue(keyType); IVector values = (IVector)factory.createVectorWithDefaultValue(valueType, dict.Count); int index = 0; try { IEnumerator <KeyValuePair <IScalar, IEntity> > itr = dict.GetEnumerator(); while (itr.MoveNext()) { keys.set(index, itr.Current.Key); values.set(index, (IScalar)itr.Current.Value); ++index; } } catch (Exception ex) { throw new IOException(ex.Message); } int flag = ((int)DATA_FORM.DF_DICTIONARY << 8) + (int)getDataType(); @out.writeShort(flag); keys.write(@out); values.write(@out); }
public override void serialize(int start, int count, ExtendedDataOutput @out) { for (int i = 0; i < count; ++i) { @out.writeInt(values[start + i]); } }
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) { foreach (IEntity value in values) { value.write(@out); } }
public virtual void write(ExtendedDataOutput @out) { if (valueType == DATA_TYPE.DT_DICTIONARY) { throw new IOException("Can't streamlize the dictionary with value type " + valueType.name()); } BasicEntityFactory factory = new BasicEntityFactory(); Vector keys = (Vector)factory.createVectorWithDefaultValue(keyType, dict.Count); Vector values = (Vector)factory.createVectorWithDefaultValue(valueType, dict.Count); int index = 0; try { foreach (KeyValuePair <Scalar, Entity> entry in dict.SetOfKeyValuePairs()) { keys.set(index, entry.Key); values.set(index, (Scalar)entry.Value); ++index; } } catch (Exception ex) { throw new IOException(ex.Message); } int flag = ((int)DATA_FORM.DF_DICTIONARY << 8) + DataType.ordinal(); @out.writeShort(flag); keys.write(@out); values.write(@out); }
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) { foreach (string str in values) { @out.writeString(str); } }
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) { foreach (double value in values) { @out.writeDouble(value); } }
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) { foreach (short value in values) { @out.writeInt(value); } }
public void writeCompressed(ExtendedDataOutput output) { short flag = ((short)(DATA_FORM.DF_TABLE) << 8 | 8 & 0xff); //8: table type TODO: add table type output.writeShort(flag); int rows = this.rows(); int cols = this.columns(); output.writeInt(rows); output.writeInt(cols); output.writeString(""); //table name for (int i = 0; i < cols; i++) { output.writeString(this.getColumnName(i)); } for (int i = 0; i < cols; i++) { AbstractVector v = (AbstractVector)this.getColumn(i); if (v.getDataType() == DATA_TYPE.DT_SYMBOL) { v.write((ExtendedDataOutput)output); } else { v.writeCompressed((ExtendedDataOutput)output); } output.flush(); } }
public void write(ExtendedDataOutput @out) { int flag = ((int)DATA_FORM.DF_SCALAR << 8) + (int)getDataType(); @out.writeInt(flag); writeScalarToOutputStream(@out); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void write(com.xxdb.io.ExtendedDataOutput out) throws java.io.IOException public virtual void write(ExtendedDataOutput @out) { Vector keys = keys(); int flag = ((int)DATA_FORM.DF_SET << 8) + DataType.ordinal(); @out.writeShort(flag); keys.write(@out); }
public virtual void write(ExtendedDataOutput @out) { IVector _keys = keys(); int flag = ((int)DATA_FORM.DF_SET << 8) + (int)getDataType(); @out.writeShort(flag); _keys.write(@out); }
public bool connect() { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(hostName, port); socket.NoDelay = true; @out = new LittleEndianDataOutputStream(new BufferedStream(new NetworkStream(socket))); ExtendedDataInput @in = new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))); string body = "connect\n"; @out.writeBytes("API 0 "); @out.writeBytes(body.Length.ToString()); @out.writeByte('\n'); @out.writeBytes(body); @out.flush(); string line = @in.readLine(); int endPos = line.IndexOf(' '); if (endPos <= 0) { close(); throw new IOException("Invalid ack msg : " + line); //return false; } sessionID = line.Substring(0, endPos); int startPos = endPos + 1; endPos = line.IndexOf(' ', startPos); if (endPos != line.Length - 2) { close(); throw new IOException("Invalid ack msg : " + line); //return false; } if (line[endPos + 1] == '0') { remoteLittleEndian = false; @out = new BigEndianDataOutputStream(new BufferedStream(new NetworkStream(socket))); } else { remoteLittleEndian = true; } if (this.userId.Length > 0 && this.password.Length > 0) { login(); } if (this.initialScript != "") { run(initialScript); } return(true); }
public override void serialize(int start, int count, ExtendedDataOutput @out) { Long2[] buffer = new Long2[count]; for (int i = 0; i < count; ++i) { buffer[i] = values[i + start]; } @out.writeLong2Array(buffer); }
public virtual void write(ExtendedDataOutput @out) { int flag = ((int)df_ << 8) + (int)getDataType(); @out.writeShort(flag); @out.writeInt(rows()); @out.writeInt(columns()); writeVectorToOutputStream(@out); }
public virtual void write(ExtendedDataOutput @out) { int count = syms.Count; @out.writeInt(0); @out.writeInt(count); for (int i = 0; i < count; ++i) { @out.writeString(syms[i]); } }
//2021.01.19 cwj override? protected void writeScalarToOutputStream(ExtendedDataOutput @out, bool blob) { if (blob) { @out.writeBlob(value); } else { @out.writeString(value); } }
public virtual void write(ExtendedDataOutput @out, SymbolBaseCollection collection) { int dataType = (int)getDataType() + 128; int flag = ((int)DATA_FORM.DF_VECTOR << 8) + dataType; @out.writeShort(flag); @out.writeInt(rows()); @out.writeInt(columns()); collection.write(@out, @base); @out.writeIntArray(values.ToArray()); }
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) { int indexCount = rowIndices.Count; int cols = valueVec.rows(); int countBytes = 1; UInt32 maxCount = 255; int indicesPos = 0; int valuesOffect = 0; while (indicesPos < indexCount) { int byteRequest = 4; int curRows = 0; int indiceCount = 1; while (byteRequest < BUF_SIZE && indicesPos + indiceCount - 1 < indexCount && indiceCount < 65536) { int curIndiceOffect = indicesPos + indiceCount - 1; int index = curIndiceOffect == 0 ? rowIndices[curIndiceOffect] : rowIndices[curIndiceOffect] - rowIndices[curIndiceOffect - 1]; while (index > maxCount) { byteRequest += (indiceCount - 1) * countBytes; countBytes *= 2; maxCount = Math.Min(UInt32.MaxValue, (UInt32)1 << (8 * countBytes) - 1); } curRows += index; indiceCount++; byteRequest += countBytes + baseUnitLength_ * index; } indiceCount--; @out.writeShort(indiceCount); @out.writeByte(countBytes); @out.writeByte(0); for (int i = 0; i < indiceCount; ++i) { int index = indicesPos + i == 0 ? rowIndices[indicesPos + i] : rowIndices[indicesPos + i] - rowIndices[indicesPos + i - 1]; if (countBytes == 1) { @out.writeByte(index); } else if (countBytes == 2) { @out.writeShort(index); } else { @out.writeInt(index); } } valueVec.serialize(valuesOffect, curRows, @out); indicesPos += indiceCount; valuesOffect += curRows; } }
public virtual void write(ExtendedDataOutput @out) { int flag = ((int)df_ << 8) + (int)getDataType(); if (this is BasicSymbolVector) { flag += 128; } @out.writeShort(flag); @out.writeInt(rows()); @out.writeInt(columns()); writeVectorToOutputStream(@out); }
public virtual bool tryReconnect() { socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(hostName, port); @out = new LittleEndianDataOutputStream(new BufferedStream(new NetworkStream(socket))); @in = new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))); string body = "connect\n"; @out.writeBytes("API 0 "); @out.writeBytes(body.Length.ToString()); @out.writeByte('\n'); @out.writeBytes(body); @out.flush(); string line = @in.readLine(); int endPos = line.IndexOf(' '); if (endPos <= 0) { close(); return(false); } sessionID = line.Substring(0, endPos); int startPos = endPos + 1; endPos = line.IndexOf(' ', startPos); if (endPos != line.Length - 2) { close(); return(false); } if (line[endPos + 1] == '0') { remoteLittleEndian = false; @out = new BigEndianDataOutputStream(new BufferedStream(new NetworkStream(socket))); } else { remoteLittleEndian = true; } @in = remoteLittleEndian ? new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket))); return(true); }
public virtual void write(ExtendedDataOutput @out) { int flag = ((int)DATA_FORM.DF_TABLE << 8) + (int)getDataType(); @out.writeShort(flag); @out.writeInt(rows()); @out.writeInt(columns()); @out.writeString(""); //table name foreach (string colName in names_) { @out.writeString(colName); } foreach (IVector vector in columns_) { vector.write(@out); } }
public virtual void write(ExtendedDataOutput output) { int length = 27 + AbstractExtendedDataOutputStream.getUTFlength(path, 0, 0) + sites.Count; foreach (string site in sites) { length += AbstractExtendedDataOutputStream.getUTFlength(site, 0, 0); } output.writeShort(length); output.writeString(path); output.write(id); output.writeInt(version); output.writeInt(size_Renamed); output.writeByte(flag); output.writeByte(sites.Count); foreach (string site in sites) { output.writeUTF(site); } }
public virtual void write(ExtendedDataOutput @out) { int flag = ((int)DATA_FORM.DF_MATRIX << 8) + (int)getDataType(); @out.writeShort(flag); byte labelFlag = (byte)((hasRowLabel() ? 1 : 0) + (hasColumnLabel() ? 2 : 0)); @out.writeByte(labelFlag); if (hasRowLabel()) { rowLabels.write(@out); } if (hasColumnLabel()) { columnLabels.write(@out); } @out.writeShort(flag); @out.writeInt(rows()); @out.writeInt(columns()); writeVectorToOutputStream(@out); }
public virtual void write(ExtendedDataOutput @out, SymbolBase @base) { bool existing = false; int id = 0; if (existingBases == null) { existingBases = new Dictionary <SymbolBase, int>(); existingBases[@base] = 0; } else { int?curId = existingBases[@base]; if (curId != null) { existing = true; id = curId.Value; } else { id = existingBases.Count; existingBases[@base] = id; } } @out.writeInt(id); if (existing) { @out.writeInt(0); } else { int size = @base.size(); @out.writeInt(size); for (int i = 0; i < size; ++i) { @out.writeString(@base.getSymbol(i)); } } }
protected internal abstract void writeVectorToOutputStream(ExtendedDataOutput @out);
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) { @out.write(values); }
protected override void writeScalarToOutputStream(ExtendedDataOutput @out) { @out.writeLong(value); }
protected abstract void writeScalarToOutputStream(ExtendedDataOutput @out);
protected internal override void writeVectorToOutputStream(ExtendedDataOutput @out) { @base.write(@out); @out.writeIntArray(values.ToArray()); }