java islocalclass_java class类的调用

importjava.io.ByteArrayOutputStream;importjava.io.File;importjava.io.FileInputStream;classLnkParser{publicLnkParser(Filef)throwsException{parse(f);}privatebooleanis_dir;p...

import java.io.ByteArrayOutputStream;

import java.io.File;

import java.io.FileInputStream;

class LnkParser {

public LnkParser(File f) throws Exception {

parse(f);

}

private boolean is_dir;

public boolean isDirectory() {

return is_dir;

}

private String real_file;

public String getRealFilename() {

return real_file;

}

private void parse(File f) throws Exception {

// read the entire file into a byte buffer

FileInputStream fin = new FileInputStream(f);

ByteArrayOutputStream bout = new ByteArrayOutputStream();

byte[] buff = new byte[256];

while (true) {

int n = fin.read(buff);

if (n == -1) {

break;

}

bout.write(buff, 0, n);

}

fin.close();

byte[] link = bout.toByteArray();

// get the flagsbyte

byte flags = link[0x14];

// get the file attributes byte

final int file_atts_offset = 0x18;

byte file_atts = link[file_atts_offset];

byte is_dir_mask = (byte) 0x10;

if ((file_atts & is_dir_mask) > 0) {

is_dir = true;

} else {

is_dir = false;

}

// if the shell settings are present, skip them

final int shell_offset = 0x4c;

final byte has_shell_mask = (byte) 0x01;

int shell_len = 0;

if ((flags & has_shell_mask) > 0) {

// the plus 2 accounts for the length marker itself

shell_len = bytes2short(link, shell_offset) + 2;

} // get to the file settings

int file_start = 0x4c + shell_len;

// get the local volume and local system values

final int basename_offset_offset = 0x10;

final int finalname_offset_offset = 0x18;

int basename_offset = link[file_start + basename_offset_offset]

+ file_start;

int finalname_offset = link[file_start + finalname_offset_offset]

+ file_start;

String basename = getNullDelimitedString(link, basename_offset);

String finalname = getNullDelimitedString(link, finalname_offset);

real_file = basename + finalname;

}

private static String getNullDelimitedString(byte[] bytes, int off) {

int len = 0;

// count bytes until the null character (0)

while (true) {

if (bytes[off + len] == 0) {

break;

}

len++;

}

return new String(bytes, off, len);

}

/*

* * convert two bytes into a short note, this is little endian because it's

* * for an Intel only OS.

*/

private static int bytes2short(byte[] bytes, int off) {

return ((bytes[off + 1] & 0xff) << 8) | (bytes[off] & 0xff);

}

}

整个这个类该怎么调用!!代码不是我写的,是国外的高人写的,我只是去拿过来用而已,但是却被如何用这个代码给难倒了,因为涉及到的参数和方法太多,不至于要一个个去赋值吧!!我才学java一个月,所以恳请高手指点一下!!

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值