舟行湍流

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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

posted on 2005-11-21 12:03  逆水行舟  阅读(341)  评论(0编辑  收藏  举报