private static void EncodeLen(int l, DataOutput @out) { while (l >= 0xFF) { @out.WriteByte(unchecked ((byte)(sbyte)0xFF)); l -= 0xFF; } @out.WriteByte((byte)(sbyte)l); }
private static void EncodeLen(int l, DataOutput @out) { while (l >= 0xFF) { @out.WriteByte(/*(byte)*/ 0xFF); // LUCENENET: Removed unnecessary cast l -= 0xFF; } @out.WriteByte((byte)l); }
public override void Write(TermData data, DataOutput output) { int bit0 = AllZero(data.LONGS) ? 0 : 1; int bit1 = ((data.BYTES == null || data.BYTES.Length == 0) ? 0 : 1) << 1; int bit2 = ((data.DOC_FREQ == 0) ? 0 : 1) << 2; int bits = bit0 | bit1 | bit2; if (bit1 > 0) // determine extra length { if (data.BYTES.Length < 32) { bits |= (data.BYTES.Length << 3); output.WriteByte((sbyte)bits); } else { output.WriteByte((sbyte)bits); output.WriteVInt(data.BYTES.Length); } } else { output.WriteByte((sbyte)bits); } if (bit0 > 0) // not all-zero case { for (int pos = 0; pos < _longsSize; pos++) { output.WriteVLong(data.LONGS[pos]); } } if (bit1 > 0) // bytes exists { output.WriteBytes(data.BYTES, 0, data.BYTES.Length); } if (bit2 > 0) // stats exist { if (_hasPos) { if (data.DOC_FREQ == data.TOTAL_TERM_FREQ) { output.WriteVInt((data.DOC_FREQ << 1) | 1); } else { output.WriteVInt((data.DOC_FREQ << 1)); output.WriteVLong(data.TOTAL_TERM_FREQ - data.DOC_FREQ); } } else { output.WriteVInt(data.DOC_FREQ); } } }
public override void Write(TermData data, DataOutput output) { int bit0 = AllZero(data.longs) ? 0 : 1; int bit1 = ((data.bytes == null || data.bytes.Length == 0) ? 0 : 1) << 1; int bit2 = ((data.docFreq == 0) ? 0 : 1) << 2; int bits = bit0 | bit1 | bit2; if (bit1 > 0) // determine extra length { if (data.bytes.Length < 32) { bits |= (data.bytes.Length << 3); output.WriteByte((byte)bits); } else { output.WriteByte((byte)bits); output.WriteVInt32(data.bytes.Length); } } else { output.WriteByte((byte)bits); } if (bit0 > 0) // not all-zero case { for (int pos = 0; pos < _longsSize; pos++) { output.WriteVInt64(data.longs[pos]); } } if (bit1 > 0) // bytes exists { output.WriteBytes(data.bytes, 0, data.bytes.Length); } if (bit2 > 0) // stats exist { if (_hasPos) { if (data.docFreq == data.totalTermFreq) { output.WriteVInt32((data.docFreq << 1) | 1); } else { output.WriteVInt32((data.docFreq << 1)); output.WriteVInt64(data.totalTermFreq - data.docFreq); } } else { output.WriteVInt32(data.docFreq); } } }
// same as DataOutput.WriteVInt64 but accepts negative values /// <summary> /// NOTE: This was writeVLong() in Lucene. /// </summary> internal static void WriteVInt64(DataOutput @out, long i) { int k = 0; while ((i & ~0x7FL) != 0L && k++ < 8) { @out.WriteByte(unchecked ((byte)(sbyte)((i & 0x7FL) | 0x80L))); i = (long)((ulong)i >> 7); } @out.WriteByte((byte)(sbyte)i); }
internal static void WriteVInt64(DataOutput @out, long i) { int k = 0; while ((i & ~0x7FL) != 0L && k++ < 8) { @out.WriteByte((byte)((i & 0x7FL) | 0x80L)); i = i.TripleShift(7); } @out.WriteByte((byte)i); }
public static void Write(DataOutput output, BytesRef b) { for (var i = 0; i < b.Length; i++) { var bx = b.Bytes[b.Offset + i]; if (bx == NEWLINE || bx == ESCAPE) { output.WriteByte(ESCAPE); } output.WriteByte(bx); } }
//----------------------------------------------------------------------- /// <summary> /// Writes the state to the stream. /// </summary> /// <param name="epochSec"> the epoch seconds, not null </param> /// <param name="out"> the output stream, not null </param> /// <exception cref="IOException"> if an error occurs </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: static void writeEpochSec(long epochSec, java.io.DataOutput out) throws java.io.IOException internal static void WriteEpochSec(long epochSec, DataOutput @out) { if (epochSec >= -4575744000L && epochSec < 10413792000L && epochSec % 900 == 0) // quarter hours between 1825 and 2300 { int store = unchecked ((int)((epochSec + 4575744000L) / 900)); @out.WriteByte(((int)((uint)store >> 16)) & 255); @out.WriteByte(((int)((uint)store >> 8)) & 255); @out.WriteByte(store & 255); } else { @out.WriteByte(255); @out.WriteLong(epochSec); } }
private void WriteRecursively(DataOutput @out, JaspellTernarySearchTrie.TSTNode node) { if (node == null) { return; } @out.WriteString(new string(new char[] { node.splitchar }, 0, 1)); sbyte mask = 0; if (node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID] != null) { mask |= LO_KID; } if (node.relatives[JaspellTernarySearchTrie.TSTNode.EQKID] != null) { mask |= EQ_KID; } if (node.relatives[JaspellTernarySearchTrie.TSTNode.HIKID] != null) { mask |= HI_KID; } if (node.data != null) { mask |= HAS_VALUE; } @out.WriteByte((byte)mask); if (node.data != null) { @out.WriteInt64((long)(node.data)); } WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID]); WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.EQKID]); WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.HIKID]); }
/// <summary> /// Writes the state to the stream. /// </summary> /// <param name="out"> the output stream, not null </param> /// <exception cref="IOException"> if an error occurs </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: void writeExternal(java.io.DataOutput out) throws java.io.IOException internal void WriteExternal(DataOutput @out) { @out.WriteInt(StandardTransitions.Length); foreach (long trans in StandardTransitions) { Ser.WriteEpochSec(trans, @out); } foreach (ZoneOffset offset in StandardOffsets) { Ser.WriteOffset(offset, @out); } @out.WriteInt(SavingsInstantTransitions.Length); foreach (long trans in SavingsInstantTransitions) { Ser.WriteEpochSec(trans, @out); } foreach (ZoneOffset offset in WallOffsets) { Ser.WriteOffset(offset, @out); } @out.WriteByte(LastRules.Length); foreach (ZoneOffsetTransitionRule rule in LastRules) { rule.WriteExternal(@out); } }
/// <summary> /// Write a value using exactly <paramref name="bitsPerValue"/> bits. /// <para/> /// NOTE: This was writeLong() in Lucene. /// </summary> public void WriteInt64(long value, int bitsPerValue) { Debug.Assert(bitsPerValue == 64 || (value >= 0 && value <= PackedInt32s.MaxValue(bitsPerValue))); while (bitsPerValue > 0) { if (remainingBits == 0) { @out.WriteByte((byte)(sbyte)current); current = 0L; remainingBits = 8; } int bits = Math.Min(remainingBits, bitsPerValue); current = current | ((((long)((ulong)value >> (bitsPerValue - bits))) & ((1L << bits) - 1)) << (remainingBits - bits)); bitsPerValue -= bits; remainingBits -= bits; } }
/// <summary> /// Write a value using exactly <code>bitsPerValue</code> bits. /// </summary> public void WriteLong(long value, int bitsPerValue) { Debug.Assert(bitsPerValue == 64 || (value >= 0 && value <= PackedInts.MaxValue(bitsPerValue))); while (bitsPerValue > 0) { if (RemainingBits == 0) { @out.WriteByte((sbyte)Current); Current = 0L; RemainingBits = 8; } int bits = Math.Min(RemainingBits, bitsPerValue); Current = Current | ((((long)((ulong)value >> (bitsPerValue - bits))) & ((1L << bits) - 1)) << (RemainingBits - bits)); bitsPerValue -= bits; RemainingBits -= bits; } }
public void Write(byte? @object, DataOutput stream) { bool isNull = @object == null; stream.WriteBoolean(isNull); if (!isNull) { stream.WriteByte(@object.Value); } }
public override bool Store(DataOutput output) { CodecUtil.WriteHeader(output, CODEC_NAME, VERSION_CURRENT); output.WriteVInt64(count); output.WriteByte(separator); output.WriteVInt32(grams); output.WriteVInt64(totTokens); fst.Save(output); return(true); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: void writeExternal(java.io.DataOutput out) throws java.io.IOException internal void WriteExternal(DataOutput @out) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int offsetSecs = totalSeconds; int offsetSecs = TotalSeconds_Renamed; int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127; // compress to -72 to +72 @out.WriteByte(offsetByte); if (offsetByte == 127) { @out.WriteInt(offsetSecs); } }
//----------------------------------------------------------------------- /// <summary> /// Writes the state to the stream. /// </summary> /// <param name="offset"> the offset, not null </param> /// <param name="out"> the output stream, not null </param> /// <exception cref="IOException"> if an error occurs </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: static void writeOffset(java.time.ZoneOffset offset, java.io.DataOutput out) throws java.io.IOException internal static void WriteOffset(ZoneOffset offset, DataOutput @out) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int offsetSecs = offset.getTotalSeconds(); int offsetSecs = offset.TotalSeconds; int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127; // compress to -72 to +72 @out.WriteByte(offsetByte); if (offsetByte == 127) { @out.WriteInt(offsetSecs); } }
private static void EncodeLiterals(byte[] bytes, int token, int anchor, int literalLen, DataOutput @out) { @out.WriteByte((byte)(sbyte)token); // encode literal length if (literalLen >= 0x0F) { EncodeLen(literalLen - 0x0F, @out); } // encode literals @out.WriteBytes(bytes, anchor, literalLen); }
public override bool Store(DataOutput output) { output.WriteVInt64(count); if (fst == null) { return(false); } fst.Save(output); output.WriteVInt32(maxAnalyzedPathsForOneInput); output.WriteByte((byte)(hasPayloads ? 1 : 0)); return(true); }
private void WriteArray(byte[] array, DataOutput output) { if (array == null) { output.WriteInt(-1); return; } output.WriteInt(array.Length); foreach (byte i in array) { output.WriteByte(i); } }
private static void EncodeSequence(byte[] bytes, int anchor, int matchRef, int matchOff, int matchLen, DataOutput @out) { int literalLen = matchOff - anchor; Debug.Assert(matchLen >= 4); // encode token int token = (Math.Min(literalLen, 0x0F) << 4) | Math.Min(matchLen - 4, 0x0F); EncodeLiterals(bytes, token, anchor, literalLen, @out); // encode match dec int matchDec = matchOff - matchRef; Debug.Assert(matchDec > 0 && matchDec < 1 << 16); @out.WriteByte((byte)(sbyte)matchDec); @out.WriteByte((byte)(sbyte)((int)((uint)matchDec >> 8))); // encode match len if (matchLen >= MIN_MATCH + 0x0F) { EncodeLen(matchLen - 0x0F - MIN_MATCH, @out); } }
// pre-order traversal private void WriteRecursively(DataOutput @out, TernaryTreeNode node) { // write out the current node @out.WriteString(new string(new char[] { node.splitchar }, 0, 1)); // prepare a mask of kids sbyte mask = 0; if (node.eqKid != null) { mask |= EQ_KID; } if (node.loKid != null) { mask |= LO_KID; } if (node.hiKid != null) { mask |= HI_KID; } if (node.token != null) { mask |= HAS_TOKEN; } if (node.val != null) { mask |= HAS_VALUE; } @out.WriteByte((byte)mask); if (node.token != null) { @out.WriteString(node.token); } if (node.val != null) { @out.WriteInt64((long)node.val); } // recurse and write kids if (node.loKid != null) { WriteRecursively(@out, node.loKid); } if (node.eqKid != null) { WriteRecursively(@out, node.eqKid); } if (node.hiKid != null) { WriteRecursively(@out, node.hiKid); } }
private void WriteInternal( byte[] @object, DataOutput output) { if (@object == null) { output.WriteInt(-1); return; } output.WriteInt(@object.Length); foreach (byte i in @object) { output.WriteByte(i); } }
public void Byte() { List <Dictionary <string, string> > testbytes = settings.GetValues(MethodBase.GetCurrentMethod(), "byte"); if (testbytes != null) { foreach (Dictionary <string, string> dEntry in testbytes) { DataOutput dataOutput = new DataOutput(); byte testbyte = Util.String2Byte(dEntry["value"]); dataOutput.WriteByte(testbyte); byte[] buffer = dataOutput.GetBuffer(); Assert.AreEqual(testbyte, buffer[0]); DataInput dataInput = new DataInput(buffer); byte result = dataInput.ReadByte(); Assert.AreEqual(testbyte, result); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private static void writeInternal(byte type, Object object, java.io.DataOutput out) throws java.io.IOException private static void WriteInternal(sbyte type, Object @object, DataOutput @out) { @out.WriteByte(type); switch (type) { case ZRULES: ((ZoneRules)@object).WriteExternal(@out); break; case ZOT: ((ZoneOffsetTransition)@object).WriteExternal(@out); break; case ZOTRULE: ((ZoneOffsetTransitionRule)@object).WriteExternal(@out); break; default: throw new InvalidClassException("Unknown serialized type"); } }
public static void WriteValue( object value, DataOutput output) { if (value == null) { output.WriteByte(NULL_TYPE); } else if (value is int intValue) { output.WriteByte(INT_TYPE); output.WriteInt(intValue); } else if (value is double doubleValue) { output.WriteByte(DOUBLE_TYPE); output.WriteDouble(doubleValue); } else if (value is string stringValue) { output.WriteByte(STRING_TYPE); output.WriteUTF(stringValue); } else if (value is bool boolValue) { output.WriteByte(BOOLEAN_TYPE); output.WriteBoolean(boolValue); } else if (value is IDictionary <string, object> dictionary) { output.WriteByte(OBJECT_TYPE); Write(dictionary, output); } else if (value is object[] objectArray) { output.WriteByte(ARRAY_TYPE); WriteArray(objectArray, output); } else { throw new IOException("Unrecognized json object type value of type " + value.GetType() + "'"); } }
private static void EncodeLen(int l, DataOutput @out) { while (l >= 0xFF) { @out.WriteByte(unchecked((sbyte)0xFF)); l -= 0xFF; } @out.WriteByte((sbyte)l); }
private static void EncodeSequence(sbyte[] bytes, int anchor, int matchRef, int matchOff, int matchLen, DataOutput @out) { int literalLen = matchOff - anchor; Debug.Assert(matchLen >= 4); // encode token int token = (Math.Min(literalLen, 0x0F) << 4) | Math.Min(matchLen - 4, 0x0F); EncodeLiterals(bytes, token, anchor, literalLen, @out); // encode match dec int matchDec = matchOff - matchRef; Debug.Assert(matchDec > 0 && matchDec < 1 << 16); @out.WriteByte((sbyte)matchDec); @out.WriteByte((sbyte)((int)((uint)matchDec >> 8))); // encode match len if (matchLen >= MIN_MATCH + 0x0F) { EncodeLen(matchLen - 0x0F - MIN_MATCH, @out); } }
public void Write(byte @object, DataOutput stream) { stream.WriteByte(@object); }
public virtual void TestDataInputOutput2() { Random random = Random(); for (int iter = 0; iter < 5 * RANDOM_MULTIPLIER; iter++) { int blockBits = TestUtil.NextInt(random, 1, 20); int blockSize = 1 << blockBits; PagedBytes p = new PagedBytes(blockBits); DataOutput @out = p.DataOutput; int numBytes = Random().Next(10000000); byte[] answer = new byte[numBytes]; Random().NextBytes(answer); int written = 0; while (written < numBytes) { if (Random().Next(10) == 7) { @out.WriteByte(answer[written++]); } else { int chunk = Math.Min(Random().Next(1000), numBytes - written); @out.WriteBytes(answer, written, chunk); written += chunk; } } PagedBytes.Reader reader = p.Freeze(random.NextBoolean()); DataInput @in = p.DataInput; byte[] verify = new byte[numBytes]; int read = 0; while (read < numBytes) { if (Random().Next(10) == 7) { verify[read++] = @in.ReadByte(); } else { int chunk = Math.Min(Random().Next(1000), numBytes - read); @in.ReadBytes(verify, read, chunk); read += chunk; } } Assert.IsTrue(Arrays.Equals(answer, verify)); BytesRef slice = new BytesRef(); for (int iter2 = 0; iter2 < 100; iter2++) { int pos = random.Next(numBytes - 1); int len = random.Next(Math.Min(blockSize + 1, numBytes - pos)); reader.FillSlice(slice, pos, len); for (int byteUpto = 0; byteUpto < len; byteUpto++) { Assert.AreEqual(answer[pos + byteUpto], (byte)slice.Bytes[slice.Offset + byteUpto]); } } } }
public static void WriteNewline(DataOutput output) { output.WriteByte(NEWLINE); }
private static void EncodeLiterals(sbyte[] bytes, int token, int anchor, int literalLen, DataOutput @out) { @out.WriteByte((sbyte)token); // encode literal length if (literalLen >= 0x0F) { EncodeLen(literalLen - 0x0F, @out); } // encode literals @out.WriteBytes(bytes, anchor, literalLen); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: @Override void write(java.io.DataOutput out) throws java.io.IOException internal override void Write(DataOutput @out) { @out.WriteByte(Ser.ZONE_OFFSET_TYPE); WriteExternal(@out); }
/// <summary>Write to out</summary> /// <exception cref="System.IO.IOException"/> public void Write(DataOutput @out) { @out.WriteByte(Ordinal()); }