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


Java Bytes.indexOf方法代码示例

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


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

示例1: corruptFile

import com.google.common.primitives.Bytes; //导入方法依赖的package包/类
/**
 * Corrupt the specified file.  Some random bytes within the file
 * will be changed to some random values.
 *
 * @throws IllegalArgumentException if the given file is not a file
 * @throws IOException if an IOException occurs while reading or writing the file
 */
public static void corruptFile(File file,
    byte[] stringToCorrupt,
    byte[] replacement) throws IOException {
  Preconditions.checkArgument(replacement.length == stringToCorrupt.length);
  if (!file.isFile()) {
    throw new IllegalArgumentException(
        "Given argument is not a file:" + file);
  }
  byte[] data = Files.toByteArray(file);
  int index = Bytes.indexOf(data, stringToCorrupt);
  if (index == -1) {
    throw new IOException(
        "File " + file + " does not contain string " +
        new String(stringToCorrupt));
  }

  for (int i = 0; i < stringToCorrupt.length; i++) {
    data[index + i] = replacement[i];
  }
  Files.write(data, file);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:29,代码来源:UpgradeUtilities.java

示例2: getFirstMatch

import com.google.common.primitives.Bytes; //导入方法依赖的package包/类
public int getFirstMatch(byte[] content) {
    byte[] beginning = content;
    if (content.length > maxOffset) {
        beginning = Arrays.copyOfRange(content, 0, maxOffset);
    }
    OR:
    for (int i = 0; i < clues.length; i++) {
        byte[][] group = clues[i];
        for (byte[] clue : group) {
            if (Bytes.indexOf(beginning, clue) == -1)
                continue OR;
        }
        // success, all members of one group matched
        return i;
    }
    return -1;
}
 
开发者ID:eorliac,项目名称:patent-crawler,代码行数:18,代码来源:ContentDetector.java

示例3: recv

import com.google.common.primitives.Bytes; //导入方法依赖的package包/类
public byte[] recv(Socket socket) throws DisconnectedException, ReadTimeoutException {
	try {
		BufferedInputStream inStream = new BufferedInputStream(socket.getInputStream());
		if (timestamp == 0)
			timestamp = System.currentTimeMillis();
		while (!new String(buffer).contains(packetDelimiter)) {
			// Disconnected
			long time = System.currentTimeMillis() - timestamp;
			if (time >= TIMEOUT) {
				clear();
				throw new DisconnectedException();
			}
			// Timeout
			if (inStream.available() < 2)
				throw new ReadTimeoutException();
			timestamp = System.currentTimeMillis();
			// Read
			byte[] read = new byte[100000];
			int numRead = inStream.read(read);
			read = Arrays.copyOfRange(read, 0, numRead);
			// Combine saved and new bytes
			byte[] newBytes = new byte[buffer.length + read.length];
			System.arraycopy(buffer, 0, newBytes, 0, buffer.length);
			System.arraycopy(read, 0, newBytes, buffer.length, read.length);
			// Save
			buffer = newBytes;
		}
		int index = Bytes.indexOf(buffer, packetDelimiter.getBytes());
		byte[] packet = Arrays.copyOfRange(buffer, 0, index);
		buffer = Arrays.copyOfRange(buffer, index + packetDelimiter.length(), buffer.length);
		return decode(packet);
	}
	catch (IOException e) {
		Logger.exception(e);
		clear();
		throw new DisconnectedException();
	}
}
 
开发者ID:rolandoislas,项目名称:drc-sim-client,代码行数:39,代码来源:NetUtil.java


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