using java.io;
using java.util.zip;
using com.ms.vjsharp.@struct;
#region 压缩解压
private static sbyte[] CompressString(string s)
{
Deflater f = new Deflater(Deflater.BEST_COMPRESSION);
sbyte[] data = JavaStructMarshalHelper.convertToByteArray(s);
f.setInput(data);
f.finish();
ByteArrayOutputStream o = new ByteArrayOutputStream(data.Length);
try
{
sbyte[] buf = new sbyte[1024];
while (!f.finished())
{
int got = f.deflate(buf);
o.write(buf, 0, got);
}
}
finally
{
o.close();
}
return o.toByteArray();
}
private static string DecompressString(sbyte[] s)
{
Inflater f = new Inflater();
f.setInput(s);
ByteArrayOutputStream o = new ByteArrayOutputStream(s.Length);
try
{
sbyte[] buf = new sbyte[1024];
while (!f.finished())
{
int got = f.inflate(buf);
o.write(buf, 0, got);
}
}
finally
{
o.close();
}
return JavaStructMarshalHelper.convertToString(o.toByteArray());
}
#endregion
#region sbyte[] 与 byte[]相互转换
/// <summary>
/// 将此实例中的指定 <see cref="sbyte"/> 字符数组转换到 <see cref="byte"/> 字符数组。
/// </summary>
/// <param name="sbyteArray">要转换的 <see cref="sbyte"/> 字符数组</param>
/// <returns>返回转换后的 <see cref="byte"/> 字符数组</returns>
public static byte[] ToByteArray(sbyte[] sbyteArray)
{
byte[] byteArray = new byte[sbyteArray.Length];
for (int index = 0; index < sbyteArray.Length; index++)
byteArray[index] = (byte) sbyteArray[index];
return byteArray;
}
public static sbyte[] ToSByteArray(byte[] sbyteArray)
{
sbyte[] byteArray = new sbyte[sbyteArray.Length];
for (int index = 0; index < sbyteArray.Length; index++)
byteArray[index] = (sbyte) sbyteArray[index];
return byteArray;
}
#endregion
引用的vjslib.dll https://files.cnblogs.com/surffish/vjslib.rar