⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guid.java

📁 用于Java 组件和通过Windows COM 对象或Windows DLL 来公开的组件之间的互操作
💻 JAVA
字号:
//******************************************************************
// Released under the DevelopMentor OpenSource Software License.
// Please consult the LICENSE file in the project root directory,
// or at http://www.develop.com for details before using this
// software.
//******************************************************************

package com.develop.jawin;

import com.develop.jawin.marshal.*;
import com.develop.io.*;
import com.develop.util.*;
import java.io.*;
import java.util.*;

public class GUID {
  private final static int ARRAYSIZE = 8;
  private int Data1;
  private short Data2;
  private short Data3;
  private byte Data4[];
    
  public final static String marshal = "XSGUID,16[ISSAS8A]";
  
  private GUID() {}
  public GUID(int Data1, short Data2, short Data3, byte[] Data4) {
    this.Data1 = Data1;
    this.Data2 = Data2;
    this.Data3 = Data3;
    this.Data4 = Data4;
    if (Data4.length != ARRAYSIZE)  {
      throw new IllegalArgumentException("GUID Data4 must be 8 bytes");
    }
  }
    
  public GUID(String guid) {
    String data1 = guid.substring(1,9);
    //Integer.parseInt cannot handle top bit?
    Data1 = StructConverter.parseInt(data1);
    String data2 = guid.substring(10,14);
    Data2 = StructConverter.parseShort(data2);
    String data3 = guid.substring(15,19);
    Data3 = StructConverter.parseShort(data3);
    String data4 = guid.substring(20,24);
    long lTop = StructConverter.parseShort(data4);
    String data5 = guid.substring(25,37);
    long lBottom = StructConverter.parseLong(data5); 
    lTop = lTop << 48;
    long d4 = lTop | lBottom;
    Data4 = new byte[ARRAYSIZE];
    StructConverter.longIntoBEBytes(d4, Data4, 0);
  }

  public String toString() {
    return "GUID{" + Integer.toHexString(Data1) + " " 
      + Integer.toHexString(Data2) + " "
      + Integer.toHexString(Data3) + " "
      + HexFormatter.convertBytesToString(Data4, 8, false);
  }

  public void marshal(LittleEndianOutputStream leos, ArrayList objs)
    throws IOException
  {
    leos.writeInt(Data1);
    leos.writeShort(Data2);
    leos.writeShort(Data3);
    leos.write(Data4, 0, ARRAYSIZE);
  }
    
  public int hashCode() {
    return Data1 + Data3;
  }
    
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (getClass() != o.getClass()) {
      return false;
    }
    GUID other = (GUID) o;
    return (Data1 == other.Data1) &&
      (Data2 == other.Data2) &&
      (Data3 == other.Data3) &&
      Arrays.equals(Data4, other.Data4);
  }
    
  public static GUID marshalOut(LittleEndianInputStream leis)
     throws IOException
  {
    GUID result = new GUID();
    result.Data1 = leis.readInt();
    result.Data2 = leis.readShort();
    result.Data3 = leis.readShort();
    result.Data4 = new byte[ARRAYSIZE];
    leis.read(result.Data4);
    return result;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -