//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void pack(String value) throws java.io.IOException public virtual void Pack(string value) { if (string.ReferenceEquals(value, null)) { PackNull(); } else { ByteBuffer encoded = Utf8.encode(value); PackStringHeader(encoded.remaining()); Out.writeBytes(encoded); } }
public override ByteBuffer Encode(string input) { try { // If it's unlikely we will fit the encoded data, just use stdlib encoder if (input.Length > _fallbackAtStringLength) { return(_fallbackEncoder.encode(input)); } char[] rawChars = ( char[] )_getCharArray.invoke(input); int len = ( int )_arrayEncode.invoke(_charsetEncoder, rawChars, Offset(input), input.Length, @out); if (len == -1) { return(_fallbackEncoder.encode(input)); } _outBuf.position(0); _outBuf.limit(len); return(_outBuf); } catch (System.IndexOutOfRangeException) { // This happens when we can't fit the encoded string. // We try and avoid this altogether by falling back to the // vanilla encoder if the string looks like it'll not fit - // but this is probabilistic since we don't know until we've encoded. // So, if our guess is wrong, we fall back here instead. return(_fallbackEncoder.encode(input)); } catch (Exception e) { throw new AssertionError("This encoder depends on sun.nio.cs.ArrayEncoder, which failed to load: " + e.Message, e); } }