puede encontrar la secuencia de bytes de giga-bytes archivo de pedidos utilizando bigdoc.
Lib y el ejemplo aquí en Github en: https://github.com/riversun/bigdoc
package org.example;
import java.io.File;
import java.util.List;
import org.riversun.bigdoc.bin.BigFileSearcher;
public class Example {
public static void main(String[] args) throws Exception {
byte[] searchBytes = "hello world.".getBytes("UTF-8");
File file = new File("/var/tmp/yourBigfile.bin");
BigFileSearcher searcher = new BigFileSearcher();
List<Long> findList = searcher.searchBigFile(file, searchBytes);
System.out.println("positions = " + findList);
}
}
Si desea buscar en la memoria, que mira esto. ejemplos aquí en Github especializados: https://github.com/riversun/finbin
import java.util.List;
import org.riversun.finbin.BigBinarySearcher;
public class Example {
public static void main(String[] args) throws Exception {
BigBinarySearcher bbs = new BigBinarySearcher();
byte[] iamBigSrcBytes = "Hello world.It's a small world.".getBytes("utf-8");
byte[] searchBytes = "world".getBytes("utf-8");
List<Integer> indexList = bbs.searchBytes(iamBigSrcBytes, searchBytes);
System.out.println("indexList=" + indexList);
}
}
Devuelve todas las posiciones compensadas en la matriz de bytes
También pueden soportar una gran variedad de bytes :)
Me encanta StackOverflow. ¡Gracias! – Teekin
Muy poca optimización: no necesita calcular la función de falla del patrón si el data.length es cero ==> puede mover la verificación data.length cero a la primera línea de la función. – dexametason