Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:30:00+00:00 2026-06-13T21:30:00+00:00

The Following is a snapshot of my code , the input file is of

  • 0

The Following is a snapshot of my code , the input file is of size 45 Mb

Scanner fileScanner = new Scanner(file);
String scannedFarm;
try{

    Pattern p = Pattern.compile("^(?:.+(?:\\r?\\n|\\Z)){2,}",Pattern.MULTILINE);

    while((scannedFarm = fileScanner.findWithinHorizon(p, 0)) != null){ // Throws Exception
    ...
    ...

I’ll add any additional info that may clarify why the exception is thrown.
Related question which describes the file format may help: Java, Regular Expression HasNext starts with empty line, multi-platform support.

BTW: This works on small files like a charm, on larger it fails , does a String has maximum size returned from findWithinHorizon?

UPDATE

As was requested a small stack trace:

http://pastebin.com/dcJ1jdkf

And a small example of the file snapshot:

http://pastebin.com/EYMsbrKj

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:30:02+00:00Added an answer on June 13, 2026 at 9:30 pm

    I don’t know the workings of the Scanner class, but whatever .findwithinHorizon() does with the regex, that regex is extremely strange.

    This regex will match the entire file at once, as long as each line is at least one character long. If there are empty lines, then it will match all blocks in-between empty lines that span at least two lines. If that’s what you actually intend to do, there’s a much better way of doing that:

    Pattern p = Pattern.compile("(?:^.+$(?:\\r?\\n)?){2,}", Pattern.MULTILINE);
    

    In order to avoid unnecessary backtracking of the regex engine, you could make all the quantifiers possessive:

    Pattern p = Pattern.compile("(?:^.++$(?:\\r?+\\n)?+){2,}+", Pattern.MULTILINE);
    

    With or without possessive quantifiers, this regex matches as follows:

    Screenshot RegexBuddy

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code will not compile with G++ 4.5 or 4.6 (snapshot). It will
I have the following code in my controller: File: app/controllers/photos_controller.rb def show_snapshot_comments snapshot =
I am using bitlyj snapshot jar to shorten URLs from the following link. http://code.google.com/p/bitlyj/downloads/list
I am using the following snapshot of code to loop through files in a
I'm new to Scala, and I want to write some multi-threaded code with pattern
If I pass the following code through my GCC 4.7 snapshot, it tries to
I am facing trouble with Node.getTextContent() of org.w3c.dom. I have following code block: String
I encountered the following code snapshot: struct hostent *hp; hp = my_gethostbyname(localhost); if (hp
Following script runs great: $ python myscript.py When I try to profile my code
I notice that there is some gap after my table. See the following snapshot:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.