Android Open Source - msghandle Format Transfer






From Project

Back to project page msghandle.

License

The source code is released under:

GNU General Public License

If you think the Android project msghandle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.anlong.msghandle.util;
//from ww  w  .  j a  v  a 2s . c  om

/**
 * @Title: FormatTransfer.java 
 * @Package com.anlong.msghandle.util
 * @company ShenZhen AnLong Technology CO.,LTD.   
 * @author lixl   
 * @date 2014-3-12 ????3:44:37 
 * @version V1.0   
 * @Description: 
 *  * ?????????
 * Java???windows?????c??c++??delphi??????????????????????????
 * ?????????????
 * windows???????????
 * linux,unix???????????
 * java???????????????????
 */
public class FormatTransfer {
/**
  * ?int?????????????????byte??
  * @param n int
  * @return byte[]
  */
public static byte[] toLH(int n) {
  byte[] b = new byte[4];
  b[0] = (byte) (n & 0xff);
  b[1] = (byte) (n >> 8 & 0xff);
  b[2] = (byte) (n >> 16 & 0xff);
  b[3] = (byte) (n >> 24 & 0xff);
  return b;
} 

/**
  * ?int?????????????????byte??
  * @param n int
  * @return byte[]
  */
public static byte[] toHH(int n) {
  byte[] b = new byte[4];
  b[3] = (byte) (n & 0xff);
  b[2] = (byte) (n >> 8 & 0xff);
  b[1] = (byte) (n >> 16 & 0xff);
  b[0] = (byte) (n >> 24 & 0xff);
  return b;
} 

/**
  * ?short?????????????????byte??
  * @param n short
  * @return byte[]
  */
public static byte[] toLH(short n) {
  byte[] b = new byte[2];
  b[0] = (byte) (n & 0xff);
  b[1] = (byte) (n >> 8 & 0xff);
  return b;
} 

/**
  * ?short?????????????????byte??
  * @param n short
  * @return byte[]
  */
public static byte[] toHH(short n) {
  byte[] b = new byte[2];
  b[1] = (byte) (n & 0xff);
  b[0] = (byte) (n >> 8 & 0xff);
  return b;
} 



/**
  * ??int?????????????????byte?? 

public static byte[] toHH(int number) {
  int temp = number;
  byte[] b = new byte[4];
  for (int i = b.length - 1; i > -1; i--) {
    b = new Integer(temp & 0xff).byteValue();
    temp = temp >> 8;
  }
  return b;
} 

public static byte[] IntToByteArray(int i) {
    byte[] abyte0 = new byte[4];
    abyte0[3] = (byte) (0xff & i);
    abyte0[2] = (byte) ((0xff00 & i) >> 8);
    abyte0[1] = (byte) ((0xff0000 & i) >> 16);
    abyte0[0] = (byte) ((0xff000000 & i) >> 24);
    return abyte0;
} 


*/ 

/**
  * ?float?????????????????byte??
  */
public static byte[] toLH(float f) {
  return toLH(Float.floatToRawIntBits(f));
} 

/**
  * ?float?????????????????byte??
  */
public static byte[] toHH(float f) {
  return toHH(Float.floatToRawIntBits(f));
} 

/**
  * ?String??byte??
  */
public static byte[] stringToBytes(String s, int length) {
  while (s.getBytes().length < length) {
    s += " ";
  }
  return s.getBytes();
} 


/**
  * ??????????String
  * @param b byte[]
  * @return String
  */
//public static String bytesToString(byte[] b) {
//  StringBuffer result = new StringBuffer("");
//  int length = b.length;
//  for (int i=0; i<length; i++) {
//    result.append((char)(b & 0xff));
//  }
//  return result.toString();
//} 

/**
  * ?????????byte??
  * @param s String
  * @return byte[]
  */
public static byte[] stringToBytes(String s) {
  return s.getBytes();
} 

/**
  * ???????????int
  * @param b byte[]
  * @return int
  */
//public static int hBytesToInt(byte[] b) {
//  int s = 0;
//  for (int i = 0; i < 3; i++) {
//    if (b >= 0) {
//    s = s + b;
//    } else {
//    s = s + 256 + b;
//    }
//    s = s * 256;
//  }
//  if (b[3] >= 0) {
//    s = s + b[3];
//  } else {
//    s = s + 256 + b[3];
//  }
//  return s;
//} 

/**
  * ???????????int
  * @param b byte[]
  * @return int
  */
public static int lBytesToInt(byte[] b) {
  int s = 0;
  for (int i = 0; i < 3; i++) {
    if (b[3-i] >= 0) {
    s = s + b[3-i];
    } else {
    s = s + 256 + b[3-i];
    }
    s = s * 256;
  }
  if (b[0] >= 0) {
    s = s + b[0];
  } else {
    s = s + 256 + b[0];
  }
  return s;
} 


/**
  * ??????short?????
  * @param b byte[]
  * @return short
  */
public static short hBytesToShort(byte[] b) {
  int s = 0;
  if (b[0] >= 0) {
    s = s + b[0];
    } else {
    s = s + 256 + b[0];
    }
    s = s * 256;
  if (b[1] >= 0) {
    s = s + b[1];
  } else {
    s = s + 256 + b[1];
  }
  short result = (short)s;
  return result;
} 

/**
  * ??????short?????
  * @param b byte[]
  * @return short
  */
public static short lBytesToShort(byte[] b) {
  int s = 0;
  if (b[1] >= 0) {
    s = s + b[1];
    } else {
    s = s + 256 + b[1];
    }
    s = s * 256;
  if (b[0] >= 0) {
    s = s + b[0];
  } else {
    s = s + 256 + b[0];
  }
  short result = (short)s;
  return result;
} 

/**
  * ??????????float
  * @param b byte[]
  * @return float
  */
public static float hBytesToFloat(byte[] b) {
  int i = 0;
  Float F = new Float(0.0);
  i = ((((b[0]&0xff)<<8 | (b[1]&0xff))<<8) | (b[2]&0xff))<<8 | (b[3]&0xff);
  return F.intBitsToFloat(i);
} 

/**
  * ??????????float
  * @param b byte[]
  * @return float
  */
public static float lBytesToFloat(byte[] b) {
  int i = 0;
  Float F = new Float(0.0);
  i = ((((b[3]&0xff)<<8 | (b[2]&0xff))<<8) | (b[1]&0xff))<<8 | (b[0]&0xff);
  return F.intBitsToFloat(i);
} 

/**
  * ?byte???????????
  */
//public static byte[] bytesReverseOrder(byte[] b) {
//  int length = b.length;
//  byte[] result = new byte[length];
//  for(int i=0; i<length; i++) {
//    result[length-i-1] = b;
//  }
//  return result;
//} 

/**
  * ????byte??
  */
public static void printBytes(byte[] bb) {
  int length = bb.length;
  for (int i=0; i<length; i++) {
    System.out.print(bb + " ");
  }
} 

public static void logBytes(byte[] bb) {
  int length = bb.length;
  String out = "";
  for (int i=0; i<length; i++) {
    out = out + bb + " ";
  } 

} 

/**
  * ?int??????????????????????int?
  * @param i int
  * @return int
  */
//public static int reverseInt(int i) {
//  int result = FormatTransfer.hBytesToInt(FormatTransfer.toLH(i));
//  return result;
//} 

/**
  * ?short??????????????????????short?
  * @param s short
  * @return short
  */
public static short reverseShort(short s) {
  short result = FormatTransfer.hBytesToShort(FormatTransfer.toLH(s));
  return result;
} 

/**
  * ?float??????????????????????float?
  * @param f float
  * @return float
  */
public static float reverseFloat(float f) {
  float result = FormatTransfer.hBytesToFloat(FormatTransfer.toLH(f));
  return result;
} 

}




Java Source Code List

com.anlong.msghandle.common.BaseMessage.java
com.anlong.msghandle.common.HandleStaticValue.java
com.anlong.msghandle.common.HandleTimer.java
com.anlong.msghandle.common.MessageTimer.java
com.anlong.msghandle.event.MessageEventListener.java
com.anlong.msghandle.event.MessageEventSource.java
com.anlong.msghandle.event.MessageEvent.java
com.anlong.msghandle.file.InitImageFileServer.java
com.anlong.msghandle.handle.ImageRequestHandle.java
com.anlong.msghandle.handle.ImageResponseHandle.java
com.anlong.msghandle.handle.MsgRequestHandle.java
com.anlong.msghandle.handle.MsgResponseHandle.java
com.anlong.msghandle.impl.AppParamImpl.java
com.anlong.msghandle.impl.AppSystemMessageReportImpl.java
com.anlong.msghandle.impl.AuthenticationImpl.java
com.anlong.msghandle.impl.BroadcastImpl.java
com.anlong.msghandle.impl.CommonContactImpl.java
com.anlong.msghandle.impl.DepImpl.java
com.anlong.msghandle.impl.DepInfoListImpl.java
com.anlong.msghandle.impl.EditGroupImpl.java
com.anlong.msghandle.impl.EditGroupUserImpl.java
com.anlong.msghandle.impl.EditUserInfoImpl.java
com.anlong.msghandle.impl.ExitPreventGroupImpl.java
com.anlong.msghandle.impl.GetGroupInfoImpl.java
com.anlong.msghandle.impl.GetHistoryMessageImpl.java
com.anlong.msghandle.impl.GetUserInfoImpl105.java
com.anlong.msghandle.impl.GroupInfoListImpl.java
com.anlong.msghandle.impl.GroupShareImpl.java
com.anlong.msghandle.impl.HeartImpl103.java
com.anlong.msghandle.impl.LocationImpl.java
com.anlong.msghandle.impl.LoginImpl101.java
com.anlong.msghandle.impl.MessageStateReportImpl.java
com.anlong.msghandle.impl.OnlineStateImpl102.java
com.anlong.msghandle.impl.OnlineUserListImpl110.java
com.anlong.msghandle.impl.SendImageFile.java
com.anlong.msghandle.impl.SendMessageImpl203.java
com.anlong.msghandle.impl.SystemParaImpl.java
com.anlong.msghandle.impl.UnreadMessageImpl.java
com.anlong.msghandle.impl.UpdatePasswordImpl.java
com.anlong.msghandle.impl.UserInfoListImpl.java
com.anlong.msghandle.interfac.AbstractMsgHandle.java
com.anlong.msghandle.interfac.BaseActivity.java
com.anlong.msghandle.interfac.MessageHandleActivity.java
com.anlong.msghandle.interfac.MsgHandle.java
com.anlong.msghandle.message.InitRequMessageServer.java
com.anlong.msghandle.message.InitRespMessageServer.java
com.anlong.msghandle.request.BaseRequest.java
com.anlong.msghandle.request.Request100.java
com.anlong.msghandle.request.Request101.java
com.anlong.msghandle.request.Request102.java
com.anlong.msghandle.request.Request103.java
com.anlong.msghandle.request.Request105.java
com.anlong.msghandle.request.Request110.java
com.anlong.msghandle.request.Request203.java
com.anlong.msghandle.request.Request301.java
com.anlong.msghandle.response.BaseResponse.java
com.anlong.msghandle.response.Response1000.java
com.anlong.msghandle.response.Response1010.java
com.anlong.msghandle.response.Response1020.java
com.anlong.msghandle.response.Response1030.java
com.anlong.msghandle.response.Response1050.java
com.anlong.msghandle.response.Response1100.java
com.anlong.msghandle.response.Response2030.java
com.anlong.msghandle.response.Response3010.java
com.anlong.msghandle.service.InitServerManager.java
com.anlong.msghandle.service.ServerManager.java
com.anlong.msghandle.socket.InitFileSocketServer.java
com.anlong.msghandle.socket.InitMsgSocketServer.java
com.anlong.msghandle.util.ByteAndInt.java
com.anlong.msghandle.util.FormatTransfer.java
com.anlong.msghandle.util.IMLog.java
com.anlong.msghandle.util.ReflectionUtil.java
com.anlong.msghandle.util.Utils.java
com.anlong.msghandle.vo.AppMessage.java
com.anlong.msghandle.vo.Application.java
com.anlong.msghandle.vo.BroadcastMessage.java
com.anlong.msghandle.vo.DepInfo.java
com.anlong.msghandle.vo.GroupInfo.java
com.anlong.msghandle.vo.GroupShare.java
com.anlong.msghandle.vo.OnlineUser.java
com.anlong.msghandle.vo.ReportState.java
com.anlong.msghandle.vo.SimpleUserInfo.java
com.anlong.msghandle.vo.UserInfo.java
com.anlong.msghandle.vo.UserMessage.java