How to really find the position of a string in a file in java? -
How to really find the position of a string in a file in java? -
there's immense amount of forum posts, blog entries , questions in q&as (including site1) answering question wrongly , showing alarming misunderstanding of reading files means applications. reading file memory , operating on not suitable solution arbitrary big files (and lies in nature of file arbitrary large).
so i'm looking "real" solution search string in file , retrieve position counted origin of stream. create things clear , not produce 19382th useless answer:
a file file. can tb big if not specified contrarily. implies reading file memory potentially crash application and/or cause downtime of service if file size isn't validated. reading files of limited size not(!) part of question[2]. a string string. can of arbitrary length, larger buffer file content read during stream processing (not larger memory, though)!afaik there's no class in java 7 jdk, not java.util.scanner doesn't retrieve position of results , requires position found java.lang.string.indexof requires input in memory! there have streaming libraries gene substring search used in bioinformatics have such search implemented.
not wikipedia's article on string search algorithms mentiones or links stream-based processing!
edit 1: gave , used python bitstring module (available pip). reaches read troughput of 170mb/s (with read maximum of os) , tested; got script working 5 lines of code, i.e. i'm looking for! i'm still interested in (real) solutions java, though.
1 how access string in file position in java
[2] , not of many questions out there answered wrongly in pov (and hence wrong questions).
you adapt datafetcher , fetcherlistener read byte[] chunks file until find string looking for. adaptation you'd need create take care of case search string occurs in between reads. you'd need store lastly searchstring.length - 1 bytes of each read append next read's data
java string stream
Comments
Post a Comment