Solved

Searching for strings in a byte array

Posted on 2006-06-09
6
227 Views
Last Modified: 2010-05-18
I want to do some fairly crude processing on data read by an InputStreamReader. I have performance issues with character processing and the text is ASCII, so I am working with bytes.

In this quick'n'dirty processing, I'd like to be able to search for strings in a character array read by the InputStreamReader. Google enticed me with http://www.goodserver.com/imap4-ssdk/apidocs/com/goodserver/util/ByteArrayHelper.html#indexOf%28byte%5b%5c,%20byte%5b%5c%29 but that would require buying into a library with a load of whistles and bells that aren't needed.

Can anyone suggest a  more suitable jar I could use for searching for strings in a byte array?
0
Comment
Question by:rstaveley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 14

Expert Comment

by:hoomanv
ID: 16873562
you can write it yourself, by learning how it is implemented in String class using char, you can change it to use byte
java.lang.String source code: http://www.docjar.com/html/api/java/lang/String.java.html
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16873607
> I'd like to be able to search for strings in a character array
does it really decreases performance if u use    new String(charArray).indexOf()   ?
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 16873874
My suggestion would be to use the BufferedReader to increase stream performance. Secondly, as far as the algorithm goes, my recommendation depends on the type search you're doing. Which strings are you searching for? Whole words? Partial words? Across line endings or not?
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 17

Author Comment

by:rstaveley
ID: 16874093
> BufferedReader

This code needs to process large text files quickly. I've taken note of the comparisons at: http://www.javaworld.com/jw-11-2000/jw-1117-performance.html and because I don't need characters so I'd rather work with bytes and buffer locally in a byte array read into by InputStreamReader.

Here's the sum total of the processing I need to do:

(1) Junk any UUEncoded blocks
   (a) Look for \nbegin
   (b) Ignore characters until \nend
(2) Junk any lines which are longer than (say) 512 bytes
   (a) Look for \n
   (b) If it comes after > 512 bytes
(3) Copy all unjunked text into a temporary file.

The processing in (2) is very simple and I guess I could look for individual bytes for "begin" and "end" to handle (1), but I'd prefer not to write the code, if I can avoid it :-)
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 16874136
> I want to do some fairly crude processing on data read by an InputStreamReader. I

if you are only interested in the bytes then don't use InputStreamReader and instead read from the InputStream directly.

You search would basically loop thru the bytes looking for the first byte in the string(s) to match.
When you find it check next matches 2ns char etc.
When you find a mismatch go back to looking for 1st char.
0
 
LVL 17

Author Comment

by:rstaveley
ID: 16875684
Thanks, objects. I suspected as much though I had a mental block about using the reader.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question