当前位置: 首页>>代码示例>>Java>>正文


Java DataInputStream.readShort方法代码示例

本文整理汇总了Java中java.io.DataInputStream.readShort方法的典型用法代码示例。如果您正苦于以下问题:Java DataInputStream.readShort方法的具体用法?Java DataInputStream.readShort怎么用?Java DataInputStream.readShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.DataInputStream的用法示例。


在下文中一共展示了DataInputStream.readShort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: PRUDPPacketRequestAnnounce

import java.io.DataInputStream; //导入方法依赖的package包/类
protected
PRUDPPacketRequestAnnounce(
	DataInputStream		is,
	long				con_id,
	int					trans_id )

	throws IOException
{
	super( PRUDPPacketTracker.ACT_REQUEST_ANNOUNCE, con_id, trans_id );

	hash 	= new byte[20];
	peer_id	= new byte[20];

	is.read( hash );
	is.read( peer_id );

	downloaded 	= is.readLong();
	left		= is.readLong();
	uploaded	= is.readLong();
	event 		= is.readInt();
	ip_address	= is.readInt();
	num_want	= is.readInt();
	port		= is.readShort();
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:25,代码来源:PRUDPPacketRequestAnnounce.java

示例2: load

import java.io.DataInputStream; //导入方法依赖的package包/类
public static Level load(DataInputStream dis) throws IOException {
	long header = dis.readLong();
	if (header != Level.FILE_HEADER)
		throw new IOException("Bad level header");
	// unused, but the call to dis.read() needs to stay
	@SuppressWarnings("unused")
	int version = dis.read() & 0xff;

	int width = dis.readShort() & 0xffff;
	int height = dis.readShort() & 0xffff;
	Level level = new Level(width, height);
	level.map = new byte[width][height];
	level.data = new byte[width][height];
	for (int i = 0; i < width; i++) {
		dis.readFully(level.map[i]);
		dis.readFully(level.data[i]);
	}
	return level;
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:20,代码来源:Level.java

示例3: process

import java.io.DataInputStream; //导入方法依赖的package包/类
@Override
public void process(byte[] range, int len) {
    if (len % KMER_RECORD_SIZE != 0) {
        throw new RuntimeException("BAD division by work range");
    }
    try {
        DataInputStream is = new DataInputStream(new ByteArrayInputStream(range, 0, len));
        int c = len / KMER_RECORD_SIZE;
        for (int i = 0; i < c; i++) {
            long kmer = is.readLong();
            short freq = is.readShort();
            processKmer(kmer, freq);
        }
        if (is.available() > 0) {
            throw new RuntimeException("Bad KMER_RECORD_SIZE!");
        }
    } catch (IOException e) {
        throw new RuntimeException("Can't load kmers from file", e);
    }
}
 
开发者ID:ctlab,项目名称:metacherchant,代码行数:21,代码来源:KmersLoadWorker.java

示例4: socks4aSocketConnection

import java.io.DataInputStream; //导入方法依赖的package包/类
public static Socket socks4aSocketConnection(String networkHost, int networkPort, String socksHost, int socksPort)
        throws IOException {

    Socket socket = new Socket();
    socket.setSoTimeout(READ_TIMEOUT_MILLISECONDS);
    SocketAddress socksAddress = new InetSocketAddress(socksHost, socksPort);
    socket.connect(socksAddress, CONNECT_TIMEOUT_MILLISECONDS);

    DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
    outputStream.write((byte) 0x04);
    outputStream.write((byte) 0x01);
    outputStream.writeShort((short) networkPort);
    outputStream.writeInt(0x01);
    outputStream.write((byte) 0x00);
    outputStream.write(networkHost.getBytes());
    outputStream.write((byte) 0x00);

    DataInputStream inputStream = new DataInputStream(socket.getInputStream());
    byte firstByte = inputStream.readByte();
    byte secondByte = inputStream.readByte();
    if (firstByte != (byte) 0x00 || secondByte != (byte) 0x5a) {
        socket.close();
        throw new IOException("SOCKS4a connect failed, got " + firstByte + " - " + secondByte +
                ", but expected 0x00 - 0x5a");
    }
    inputStream.readShort();
    inputStream.readInt();
    return socket;
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4Android,代码行数:30,代码来源:Utilities.java

示例5: deserialiseAddress

import java.io.DataInputStream; //导入方法依赖的package包/类
protected static InetSocketAddress
deserialiseAddress(
	DataInputStream		is )

	throws IOException
{
	byte[]	bytes = deserialiseByteArray( is, 16 );

	int	port = is.readShort()&0xffff;

	return( new InetSocketAddress( InetAddress.getByAddress( bytes ), port ));
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:13,代码来源:DHTUDPUtils.java

示例6: deserialize

import java.io.DataInputStream; //导入方法依赖的package包/类
public static TrieStoreImpl deserialize(byte[] bytes, int offset, int length, KeyValueDataSource ds) {
    ByteArrayInputStream bstream = new ByteArrayInputStream(bytes, offset, length);
    DataInputStream dstream = new DataInputStream(bstream);

    try {
        dstream.readShort(); // version

        int nkeys = dstream.readInt();

        for (int k = 0; k < nkeys; k++) {
            int lkey = dstream.readInt();
            byte[] key = new byte[lkey];
            if (dstream.read(key) != lkey) {
                throw new EOFException();
            }

            int lvalue = dstream.readInt();
            byte[] value = new byte[lvalue];
            if (dstream.read(value) != lvalue) {
                throw new EOFException();
            }

            ds.put(key, value);
        }

        return new TrieStoreImpl(ds);
    }
    catch (IOException ex) {
        logger.error(ERROR_CREATING_STORE, ex);
        panicProcessor.panic(PANIC_TOPIC, ERROR_CREATING_STORE +": " + ex.getMessage());
        throw new TrieSerializationException(ERROR_CREATING_STORE, ex);
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:34,代码来源:TrieStoreImpl.java

示例7: NetworkAdminNATUDPReply

import java.io.DataInputStream; //导入方法依赖的package包/类
protected
NetworkAdminNATUDPReply(
	DataInputStream		is,
	int					trans_id )

	throws IOException
{
	super( NetworkAdminNATUDPCodecs.ACT_NAT_REPLY, trans_id );

	short	len = is.readShort();

	if ( len <= 0 ){

		throw( new IOException( "invalid length" ));
	}

	byte[]	bytes = new byte[len];

	is.read( bytes );

	payload = BDecoder.decode( bytes );
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:23,代码来源:NetworkAdminNATUDPReply.java

示例8: parse

import java.io.DataInputStream; //导入方法依赖的package包/类
public static ConstantPool parse(byte[] bytes, String description) {
    List<ConstantPool.Entry> entries = new ArrayList<ConstantPool.Entry>();
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
    entries.add(new EntryNULL());
    try {
        do {
            byte tagByte;
            try {
                tagByte = in.readByte();
            } catch (EOFException eof) {
                break;
            }
            ConstantPool.Entry entry;
            switch(tagByte) {
                case TAG_UTF8:
                    entry = new EntryUTF8(in.readUTF());
                    break;
                case TAG_INTEGER:
                    entry = new EntryInteger(in.readInt());
                    break;
                case TAG_LONG:
                    entry = new EntryLong(in.readLong());
                    entries.add(entry);
                    entry = new EntryNULL(); // Long takes TWO constant pool entries!?!
                    break;
                case TAG_FLOAT:
                    entry = new EntryFloat(in.readFloat());
                    break;
                case TAG_DOUBLE:
                    entry = new EntryDouble(in.readDouble());
                    entries.add(entry);
                    entry = new EntryNULL(); // Double takes TWO constant pool entries!?!
                    break;
                case TAG_CLASS:
                    entry = new EntryClass(in.readShort());
                    break;
                case TAG_STRING:
                    entry = new EntryString(in.readShort());
                    break;
                case TAG_NAMETYPE:
                    entry = new EntryNameType(in.readShort(), in.readShort());
                    break;
                case TAG_FIELDREF:
                case TAG_METHODREF:
                case TAG_INTERFACEREF:
                    entry = new EntryFieldMethodRef(tagByte, in.readShort(), in.readShort());
                    break;
                case TAG_METHODHANDLE:
                    entry = new EntryMethodHandle(in);
                    break;
                case TAG_METHODTYPE:
                    entry = new EntryMethodType(in);
                    break;
                case TAG_INVOKEDYNAMIC:
                    entry = new EntryInvokeDynamic(in);
                    break;
                case TAG_MODULE:
                    entry = new EntryModule(in.readShort());
                    break;
                case TAG_PACKAGE:
                    entry = new EntryPackage(in.readShort());
                    break;
                case 0:
                default:
                    Logger.getLogger(ConstantPool.class.getName()).warning("Unknown tag byte: "+tagByte);
                    entry = new EntryNULL();
            }
            entries.add(entry);
        } while(true);
    } catch (IOException ioex) {
        // Should not occur
        Exceptions.printStackTrace(ioex);
    }
    return new ConstantPool(entries, description);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:76,代码来源:ConstantPool.java

示例9: loadKmeanResult

import java.io.DataInputStream; //导入方法依赖的package包/类
private KMean loadKmeanResult(int numCluster, int varSelLst[], String fileName, ZipFile zf) throws IOException {
	ClusteringInfosKMean curInfo[];
	int i, j, k;
	int curNumCluster;
	MatrixObservations m = waSession.getDataModel().getMatrix();
	int numvars = m.getNumVariables();
	int numoss = m.getNumOfObs();
	DataInputStream dis = new DataInputStream(zf.getInputStream(new ZipEntry(fileName)));
	short asseg[][];

	//init result vector
	curInfo = new ClusteringInfosKMean[numCluster];
	asseg = new short[numCluster][numoss];

	//System.out.println("Loading kMeans Results "+fileName);
	for (i = 0; i < numCluster; i++) {
		curNumCluster = dis.readInt();
		curInfo[i] = new ClusteringInfosKMean(curNumCluster - 1, numvars);
		curInfo[i].omsr = dis.readDouble();
		curInfo[i].ratio = dis.readDouble();
		for (k = 0; k < curNumCluster; k++) {
			curInfo[i].infoCluster[k] = new ClusterInfoKMean(numvars);
			curInfo[i].infoCluster[k].numOss = dis.readInt();
			for (j = 0; j < numvars; j++) {
				curInfo[i].infoCluster[k].percVar[j] = dis.readDouble();
				curInfo[i].infoCluster[k].statClust[j].iNotZr = dis.readInt();
				curInfo[i].infoCluster[k].statClust[j].dMedia = dis.readDouble();
				curInfo[i].infoCluster[k].statClust[j].dStdEr = dis.readDouble();
				curInfo[i].infoCluster[k].statClust[j].dStdDv = dis.readDouble();
				curInfo[i].infoCluster[k].statClust[j].dVarnz = dis.readDouble();
				curInfo[i].infoCluster[k].statClust[j].dKurto = dis.readDouble();
				curInfo[i].infoCluster[k].statClust[j].dSkewn = dis.readDouble();
				curInfo[i].infoCluster[k].statClust[j].dRange = dis.readDouble();
				curInfo[i].infoCluster[k].statClust[j].dMaxOs = dis.readDouble();
				curInfo[i].infoCluster[k].statClust[j].dMinOs = dis.readDouble();
			}
		}
		for (k = 0; k < numoss; k++) {
			asseg[i][k] = dis.readShort();
		}
	}
	return new KMean(curInfo, varSelLst, asseg);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:44,代码来源:WorkloadResultLoader.java

示例10: read

import java.io.DataInputStream; //导入方法依赖的package包/类
public Object read(DataInputStream in) throws IOException
{
	return in.readShort();
}
 
开发者ID:timtomtim7,项目名称:SparseBukkitAPI,代码行数:5,代码来源:TagType.java

示例11: transactionReceived

import java.io.DataInputStream; //导入方法依赖的package包/类
public void transactionReceived(Transaction transaction, Object transactionObject) throws BadPacketException {
    try {
        DataInputStream in = new DataInputStream(
                new ByteArrayInputStream(transaction.getData()));

        ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(byteOutputStream);

        MysterType type = new MysterType(in.readInt()); //type

        FileHash md5Hash = null;

        for (;;) { //get hash name, get hash length, get hash data until
            // hashname is ""
            String hashType = in.readUTF();
            if (hashType.equals("")) {
                break;
            }
            int lengthOfHash = 0xffff & in.readShort();

            byte[] hashBytes = new byte[lengthOfHash];
            in.readFully(hashBytes, 0, hashBytes.length);

            if (hashType.equalsIgnoreCase(com.myster.hash.HashManager.MD5)) {
                md5Hash = SimpleFileHash.buildFileHash(hashType, hashBytes);
            }
        }

        com.myster.filemanager.FileItem file = null;

        if (md5Hash != null) {
            file = com.myster.filemanager.FileTypeListManager.getInstance().getFileFromHash(
                    type, md5Hash);
        }

        if (file == null) {
            out.writeUTF("");
        } else {
            out.writeUTF(file.getName());
        }

        sendTransaction(new Transaction(transaction, byteOutputStream.toByteArray(),
                Transaction.NO_ERROR));
    } catch (IOException ex) {
        throw new BadPacketException("Bad packet " + ex);
    }
}
 
开发者ID:addertheblack,项目名称:myster,代码行数:48,代码来源:SearchHashDatagramServer.java

示例12: load

import java.io.DataInputStream; //导入方法依赖的package包/类
/**
 * Loads the rules from a DateInputStream
 *
 * @param dis  the DateInputStream to load, not null
 * @throws Exception if an error occurs
 */
private static void load(DataInputStream dis) throws ClassNotFoundException, IOException {
    if (dis.readByte() != 1) {
        throw new StreamCorruptedException("File format not recognised");
    }
    // group
    String groupId = dis.readUTF();
    if ("TZDB".equals(groupId) == false) {
        throw new StreamCorruptedException("File format not recognised");
    }
    // versions, only keep the last one
    int versionCount = dis.readShort();
    for (int i = 0; i < versionCount; i++) {
        versionId = dis.readUTF();

    }
    // regions
    int regionCount = dis.readShort();
    String[] regionArray = new String[regionCount];
    for (int i = 0; i < regionCount; i++) {
        regionArray[i] = dis.readUTF();
    }
    // rules
    int ruleCount = dis.readShort();
    ruleArray = new byte[ruleCount][];
    for (int i = 0; i < ruleCount; i++) {
        byte[] bytes = new byte[dis.readShort()];
        dis.readFully(bytes);
        ruleArray[i] = bytes;
    }
    // link version-region-rules, only keep the last version, if more than one
    for (int i = 0; i < versionCount; i++) {
        regionCount = dis.readShort();
        regions = new String[regionCount];
        indices = new int[regionCount];
        for (int j = 0; j < regionCount; j++) {
            regions[j] = regionArray[dis.readShort()];
            indices[j] = dis.readShort();
        }
    }
    // remove the following ids from the map, they
    // are exclued from the "old" ZoneInfo
    zones.remove("ROC");
    for (int i = 0; i < versionCount; i++) {
        int aliasCount = dis.readShort();
        aliases.clear();
        for (int j = 0; j < aliasCount; j++) {
            String alias = regionArray[dis.readShort()];
            String region = regionArray[dis.readShort()];
            aliases.put(alias, region);
        }
    }
    // old us time-zone names
    addOldMapping();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:ZoneInfoFile.java

示例13: load

import java.io.DataInputStream; //导入方法依赖的package包/类
/**
 * Loads the rules from a DateInputStream, often in a jar file.
 *
 * @param dis  the DateInputStream to load, not null
 * @throws Exception if an error occurs
 */
private void load(DataInputStream dis) throws Exception {
    if (dis.readByte() != 1) {
        throw new StreamCorruptedException("File format not recognised");
    }
    // group
    String groupId = dis.readUTF();
    if ("TZDB".equals(groupId) == false) {
        throw new StreamCorruptedException("File format not recognised");
    }
    // versions
    int versionCount = dis.readShort();
    for (int i = 0; i < versionCount; i++) {
        versionId = dis.readUTF();
    }
    // regions
    int regionCount = dis.readShort();
    String[] regionArray = new String[regionCount];
    for (int i = 0; i < regionCount; i++) {
        regionArray[i] = dis.readUTF();
    }
    regionIds = Arrays.asList(regionArray);
    // rules
    int ruleCount = dis.readShort();
    Object[] ruleArray = new Object[ruleCount];
    for (int i = 0; i < ruleCount; i++) {
        byte[] bytes = new byte[dis.readShort()];
        dis.readFully(bytes);
        ruleArray[i] = bytes;
    }
    // link version-region-rules
    for (int i = 0; i < versionCount; i++) {
        int versionRegionCount = dis.readShort();
        regionToRules.clear();
        for (int j = 0; j < versionRegionCount; j++) {
            String region = regionArray[dis.readShort()];
            Object rule = ruleArray[dis.readShort() & 0xffff];
            regionToRules.put(region, rule);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:47,代码来源:TzdbZoneRulesProvider.java

示例14: fromMessage

import java.io.DataInputStream; //导入方法依赖的package包/类
private static TrieImpl fromMessage(byte[] message, int position, int msglength, TrieStore store) {
    if (message == null) {
        return null;
    }

    ByteArrayInputStream bstream = new ByteArrayInputStream(message, position, msglength);
    DataInputStream istream = new DataInputStream(bstream);

    try {
        int arity = istream.readByte();
        int flags = istream.readByte();
        boolean isSecure = (flags & 0x01) == 1;
        boolean hasLongVal = (flags & 0x02) == 2;
        int bhashes = istream.readShort();
        int lshared = istream.readShort();

        int nhashes = 0;
        int lencoded = TrieImpl.getEncodedPathLength(lshared, arity);

        byte[] encodedSharedPath = null;

        if (lencoded > 0) {
            encodedSharedPath = new byte[lencoded];
            if (istream.read(encodedSharedPath) != lencoded) {
                throw new EOFException();
            }
        }

        byte[][] hashes = new byte[arity][];

        for (int k = 0; k < arity; k++) {
            if ((bhashes & (1 << k)) == 0) {
                continue;
            }

            hashes[k] = new byte[SHA3Helper.DEFAULT_SIZE_BYTES];

            if (istream.read(hashes[k]) != SHA3Helper.DEFAULT_SIZE_BYTES) {
                throw new EOFException();
            }

            nhashes++;
        }

        int offset = MESSAGE_HEADER_LENGTH + lencoded + nhashes * SHA3Helper.DEFAULT_SIZE_BYTES;
        byte[] value = null;

        if (hasLongVal) {
            byte[] valueHash = new byte[SHA3Helper.DEFAULT_SIZE_BYTES];

            if (istream.read(valueHash) != SHA3Helper.DEFAULT_SIZE_BYTES) {
                throw new EOFException();
            }

            value = store.retrieveValue(valueHash);
        }
        else {
            int lvalue = msglength - offset;

            if (lvalue > 0) {
                value = new byte[lvalue];
                if (istream.read(value) != lvalue) {
                    throw new EOFException();
                }
            }
        }

        TrieImpl trie = new TrieImpl(arity, encodedSharedPath, lshared, value, null, hashes, store).withSecure(isSecure);

        if (store != null) {
            trie.saved = true;
        }

        return trie;
    } catch (IOException ex) {
        logger.error(ERROR_CREATING_TRIE, ex);
        panicProcessor.panic(PANIC_TOPIC, ERROR_CREATING_TRIE +": " + ex.getMessage());
        throw new TrieSerializationException(ERROR_CREATING_TRIE, ex);
    }
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:81,代码来源:TrieImpl.java

示例15: GenericWholeArrray

import java.io.DataInputStream; //导入方法依赖的package包/类
public GenericWholeArrray(DataInputStream dis, int stored)
		throws IOException {
	type = dis.readInt();

	switch (type) {
	case TYPE_BYTE:
		byteArray = new byte[stored];
		for (int i = 0; i < stored; i++) {
			byteArray[i] = dis.readByte();
		}
		break;

	case TYPE_SHORT:
		shortArray = new short[stored];
		for (int i = 0; i < stored; i++) {
			shortArray[i] = dis.readShort();
		}
		break;

	case TYPE_INT:
		intArray = new int[stored];
		for (int i = 0; i < stored; i++) {
			intArray[i] = dis.readInt();
		}
		break;

	case TYPE_CHAR:
		charArray = new char[stored];
		for (int i = 0; i < stored; i++) {
			charArray[i] = dis.readChar();
		}
		break;

	case TYPE_BIT:
		int ints = bitsToInts(stored);
		bitArray = new int[ints];
		for (int i = 0; i < ints; i++) {
			bitArray[i] = dis.readInt();
		}
		break;
	}
}
 
开发者ID:victorward,项目名称:recruitervision,代码行数:43,代码来源:GenericWholeArrray.java


注:本文中的java.io.DataInputStream.readShort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。