當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。