This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 194326
Collapse All | Expand All

(-)a/utilities/src/org/netbeans/modules/search/BasicSearchCriteria.java (-7 / +6 lines)
Lines 44-52 Link Here
44
44
45
package org.netbeans.modules.search;
45
package org.netbeans.modules.search;
46
46
47
import java.io.InputStream;
47
import java.io.FileNotFoundException;
48
import java.io.FileNotFoundException;
48
import java.io.IOException;
49
import java.io.IOException;
49
import java.io.FileInputStream;
50
import java.nio.charset.Charset;
50
import java.nio.charset.Charset;
51
import java.util.ArrayList;
51
import java.util.ArrayList;
52
import java.util.Collection;
52
import java.util.Collection;
Lines 62-68 Link Here
62
import javax.swing.event.ChangeEvent;
62
import javax.swing.event.ChangeEvent;
63
import javax.swing.event.ChangeListener;
63
import javax.swing.event.ChangeListener;
64
import org.netbeans.api.queries.FileEncodingQuery;
64
import org.netbeans.api.queries.FileEncodingQuery;
65
import org.netbeans.modules.search.TextDetail.DetailNode;
66
import org.openide.filesystems.FileObject;
65
import org.openide.filesystems.FileObject;
67
import org.openide.loaders.DataObject;
66
import org.openide.loaders.DataObject;
68
import org.openide.loaders.DataObjectNotFoundException;
67
import org.openide.loaders.DataObjectNotFoundException;
Lines 748-760 Link Here
748
        lastCharset = FileEncodingQuery.getEncoding(fo);
747
        lastCharset = FileEncodingQuery.getEncoding(fo);
749
        SearchPattern sp = createSearchPattern();
748
        SearchPattern sp = createSearchPattern();
750
        BufferedCharSequence bcs = null;
749
        BufferedCharSequence bcs = null;
751
        try {
750
        try {         
752
            FileInputStream fis = (FileInputStream)fo.getInputStream();
751
            InputStream stream = fo.getInputStream();
753
            bcs = new BufferedCharSequence(fis, lastCharset);
752
            bcs = new BufferedCharSequence(stream, lastCharset, fo.getSize());
754
            ArrayList<TextDetail> txtDetails = getTextDetails(bcs, fo, sp);
753
            ArrayList<TextDetail> txtDetails = getTextDetails(bcs, fo, sp);
755
            if (txtDetails.isEmpty()){
754
            if (txtDetails.isEmpty()){                
756
                return false;
755
                return false;
757
            }
756
            }            
758
            getDetailsMap().put(fo, txtDetails);
757
            getDetailsMap().put(fo, txtDetails);
759
            freeDataObject();
758
            freeDataObject();
760
            return true;
759
            return true;
(-)a/utilities/src/org/netbeans/modules/search/BufferedCharSequence.java (-80 / +61 lines)
Lines 42-57 Link Here
42
42
43
package org.netbeans.modules.search;
43
package org.netbeans.modules.search;
44
44
45
import java.io.FileInputStream;
45
import java.io.BufferedInputStream;
46
import java.io.IOException;
46
import java.io.IOException;
47
import java.io.InputStream;
47
import java.nio.ByteBuffer;
48
import java.nio.ByteBuffer;
48
import java.nio.CharBuffer;
49
import java.nio.CharBuffer;
49
import java.nio.channels.FileChannel;
50
import java.nio.charset.Charset;
50
import java.nio.charset.Charset;
51
import java.nio.charset.CharsetDecoder;
51
import java.nio.charset.CharsetDecoder;
52
import java.nio.charset.CoderResult;
52
import java.nio.charset.CoderResult;
53
import java.nio.charset.CodingErrorAction;
53
import java.nio.charset.CodingErrorAction;
54
import java.util.logging.Level;
55
import java.util.logging.Logger;
54
import java.util.logging.Logger;
56
import sun.nio.cs.ThreadLocalCoders;
55
import sun.nio.cs.ThreadLocalCoders;
57
56
Lines 138-180 Link Here
138
137
139
    /**
138
    /**
140
     * Creates {@code BufferedCharSequence} for the specified {@code stream}.
139
     * Creates {@code BufferedCharSequence} for the specified {@code stream}.
141
     * @param stream is a stream that will be buffered and represented as a 
140
     * @param stream is a stream that will be buffered and represented as a
142
     *        {@code CharSequence}.
141
     *        {@code CharSequence}.
143
     * @param charset is a named mapping that will be used to decode a sequence
142
     * @param charset is a named mapping that will be used to decode a sequence
144
     *                of bytes from the {@code stream}.
143
     *                of bytes from the {@code stream}.
144
     * @param size is the size of the file.
145
     */
145
     */
146
    public BufferedCharSequence(final FileInputStream stream, Charset charset) {
146
    public BufferedCharSequence(final InputStream stream, Charset charset, long size) {
147
        this(stream.getChannel(), charset);
148
    }
149
150
    /**
151
     * Creates {@code BufferedCharSequence} for the specified {@code channel}.
152
     * @param channel is a channel that will be buffered and represented as a
153
     *        {@code CharSequence}.
154
     * @param charset is a named mapping that will be used to decode a sequence
155
     *                of bytes from the {@code channel}.
156
     */
157
    public BufferedCharSequence(final FileChannel channel, Charset charset) {
158
        // TODO charset.name() is used instead of charset due to a bug in the
147
        // TODO charset.name() is used instead of charset due to a bug in the
159
        // org.netbeans.api.queries.FileEncodingQuery.ProxyCharset.ProxyDecoder
148
        // org.netbeans.api.queries.FileEncodingQuery.ProxyCharset.ProxyDecoder
160
        // The IllegalStateException may be thrown after correct actions.
149
        // The IllegalStateException may be thrown after correct actions.
161
        // See #169804
150
        // See #169804
162
        this(channel,
151
        this(stream,
163
            ThreadLocalCoders.decoderFor(charset.name())
152
            ThreadLocalCoders.decoderFor(charset.name())
164
                             .onMalformedInput(CodingErrorAction.REPLACE)
153
                             .onMalformedInput(CodingErrorAction.REPLACE)
165
                             .onUnmappableCharacter(CodingErrorAction.REPLACE));
154
                             .onUnmappableCharacter(CodingErrorAction.REPLACE), size);
166
    }
155
    }
167
156
168
    /**
157
169
     * Creates {@code BufferedCharSequence} for the specified {@code channel}.
158
    public BufferedCharSequence(final InputStream stream,
170
     * @param channel is a channel that will be buffered and represented as a
159
                                CharsetDecoder decoder, long size) {
171
     *        {@code CharSequence}.
160
        this.source = new Source(stream, size);
172
     * @param decoder is a decoder that will be used to decode a sequence
173
     *                of bytes from the {@code channel}.
174
     */
175
    public BufferedCharSequence(final FileChannel channel,
176
                                CharsetDecoder decoder) {
177
        this.source = new Source(channel);
178
        this.decoder = decoder;
161
        this.decoder = decoder;
179
        this.sink = new Sink(this.source);
162
        this.sink = new Sink(this.source);
180
        LOG.finer("<init> " + this.source + "; decoder = " + this.decoder +
163
        LOG.finer("<init> " + this.source + "; decoder = " + this.decoder +
Lines 232-238 Link Here
232
     * @return the underlying instance of this class.
215
     * @return the underlying instance of this class.
233
     * @throws SourceIOException
216
     * @throws SourceIOException
234
     */
217
     */
235
    public BufferedCharSequence reset() throws SourceIOException {
218
    public BufferedCharSequence reset() throws SourceIOException {        
236
        source.reset();
219
        source.reset();
237
        sink.reset();
220
        sink.reset();
238
        decoder.reset();
221
        decoder.reset();
Lines 274-280 Link Here
274
        reset();
257
        reset();
275
        int length = 0;
258
        int length = 0;
276
        while(sink.next()) {  }
259
        while(sink.next()) {  }
277
        length = sink.buffer.scope.end;
260
        length = sink.buffer.scope.end;        
278
        return length;
261
        return length;
279
    }
262
    }
280
263
Lines 409-421 Link Here
409
     */
392
     */
410
    public String getLineText(int start) {
393
    public String getLineText(int start) {
411
        int oldPosition = changePosition(start);
394
        int oldPosition = changePosition(start);
412
        String text = nextLineText();
395
        String text = nextLineText();        
413
        changePosition(oldPosition);
396
        changePosition(oldPosition);
414
        return text;
397
        return text;
415
    }
398
    }
416
399
417
    private char getCharAt(int index) throws IndexOutOfBoundsException {
400
    private char getCharAt(int index) throws IndexOutOfBoundsException {        
418
        if(sink.buffer.scope.isBefore(index)) {
401
        if(sink.buffer.scope.isBefore(index)) {            
419
            reset();
402
            reset();
420
        }
403
        }
421
        while(!sink.buffer.scope.isInside(index)) {
404
        while(!sink.buffer.scope.isInside(index)) {
Lines 424-430 Link Here
424
                throw new IndexOutOfBoundsException("index is " +
407
                throw new IndexOutOfBoundsException("index is " +
425
                        index + " > lenght"); // NOI18N
408
                        index + " > lenght"); // NOI18N
426
            }
409
            }
427
        }
410
        }        
428
        return sink.charAt(index);
411
        return sink.charAt(index);
429
    }
412
    }
430
413
Lines 466-535 Link Here
466
    /**
449
    /**
467
     * The source buffer.
450
     * The source buffer.
468
     */
451
     */
469
    private class Source {
452
       private class Source {
470
        private int maxBufferSize = MAX_SOURCE_BUFFER_SIZE;
453
        private int maxBufferSize = MAX_SOURCE_BUFFER_SIZE;
471
454
472
        private ByteBuffer buffer;
455
        private ByteBuffer buffer;
473
        private FileChannel channel;
456
        private BufferedInputStream bstream;
457
        private int bufferSize;
474
        
458
        
475
        public Source(FileChannel channel) {
459
        public Source(InputStream inputStream, long bufferSize) {
476
            this.channel = channel;
460
            this.bstream = new BufferedInputStream(inputStream);
461
            this.bstream.mark(Integer.MAX_VALUE);
462
            this.bufferSize = getBufferSize(bufferSize);
477
            buffer = newBuffer();
463
            buffer = newBuffer();
478
        }
464
        }
479
465
480
        @Override
466
        @Override
481
        public String toString() {
467
        public String toString() {
482
            return "source=[channel = "+channel+", buffer = "+buffer+"]";
468
            return "source=[stream = " + bstream.toString() + ", buffer = " + buffer + "]";
483
        }
469
        }
484
470
485
        private ByteBuffer newBuffer() {
471
        private ByteBuffer newBuffer() {
486
            return ByteBuffer.allocate(getBufferSize());
472
            return ByteBuffer.allocate(bufferSize);
487
        }
473
        }
488
474
489
        public void reset() {
475
       public void reset() {        
490
            try {
476
            try {                
491
                channel.position(0);
477
                bstream.reset();
492
            } catch (IOException ex) {
478
            } catch (IOException ex) {
493
                throw new SourceIOException(ex);
479
                throw new SourceIOException(ex);
494
            }
480
            }            
495
            buffer.clear();
481
            buffer.clear();
496
        }
482
        }
497
483
498
        /**
484
        /**
499
         * Reads a sequence of bytes from the source channel. Bytes are read 
485
         * Reads a sequence of bytes from the source stream. Bytes are read
500
         * starting at the channel's current file position, and then the 
486
         * starting at the stream's current position, and then the
501
         * position is updated with the number of bytes actually read.
487
         * position is updated with the number of bytes actually read.
502
         *  
488
         *
503
         * @return The number of bytes read, possibly zero, or -1 if the channel
489
         * @return The number of bytes read, possibly zero, or -1 if 
504
         * has reached end-of-stream
490
         * the end-of-stream is reached
505
         * 
491
         *
506
         * @throws ProcessException If some other I/O error occurs
492
         * @throws ProcessException If some other I/O error occurs
507
         */
493
         */
508
        private int read() {
494
        private int read() {
509
            try {
495
            try {
510
                return channel.read(buffer);
496
                if(buffer.hasArray()) {
497
                    int res = bstream.read(buffer.array());
498
                    if(res > 0) {
499
                        buffer.position(res);
500
                    }
501
                    return res;
502
                }
503
                throw new IOException("No byte array");
511
            } catch (IOException ex) {
504
            } catch (IOException ex) {
512
                throw new SourceIOException(ex);
505
                throw new SourceIOException(ex);
513
            }
506
            }
514
        }
507
        }
515
508
516
        public int position() throws IOException {
509
        public void close() throws IOException {
517
            return (int) channel.position();
510
            bstream.close();
518
        }
511
        }
519
512
520
        public void close() throws IOException {
513
        public int getSize(long size) {
521
            channel.close();
522
        }
523
524
        public int size() {
525
            try {
526
                return getSize(channel.size());
527
            } catch (IOException ioe) {
528
                throw new SourceIOException(ioe);
529
            }
530
        }
531
532
        private int getSize(long size) {
533
            if (size > Integer.MAX_VALUE) {
514
            if (size > Integer.MAX_VALUE) {
534
                LOG.warning("File size is " + size + "bytes. " +
515
                LOG.warning("File size is " + size + "bytes. " +
535
                            "Only first " + MAX_FILE_SIZE +
516
                            "Only first " + MAX_FILE_SIZE +
Lines 539-546 Link Here
539
            return (int) size;
520
            return (int) size;
540
        }
521
        }
541
522
542
        private int getBufferSize() {
523
        private int getBufferSize(long bufferSize) {
543
            int size = Math.min(size(), maxBufferSize);
524
            int size = Math.min(getSize(bufferSize), maxBufferSize);
544
            return size;
525
            return size;
545
        }
526
        }
546
527
Lines 548-557 Link Here
548
         *
529
         *
549
         * @return {@code true} if EOF, otherwise {@code false}.
530
         * @return {@code true} if EOF, otherwise {@code false}.
550
         */
531
         */
551
        public boolean readNext() {
532
        public boolean readNext() {           
552
            buffer.clear();
533
            buffer.clear();            
553
            int status = read();
534
            int status = read();            
554
            buffer.flip();
535
            buffer.flip();            
555
            return status == -1;
536
            return status == -1;
556
        }
537
        }
557
538
Lines 578-584 Link Here
578
            return "sink = [" + buffer + "]";
559
            return "sink = [" + buffer + "]";
579
        }
560
        }
580
561
581
        public void reset() {
562
        public void reset() {            
582
            buffer.reset();
563
            buffer.reset();
583
        }
564
        }
584
565
Lines 595-601 Link Here
595
         * @return {@code true} is successful, otherwise {@code false}.
576
         * @return {@code true} is successful, otherwise {@code false}.
596
         */
577
         */
597
        private boolean next() {
578
        private boolean next() {
598
            CharBuffer out = buffer.clear();
579
            CharBuffer out = buffer.clear();           
599
            boolean endOfInput = false;
580
            boolean endOfInput = false;
600
            if(coderResult == CoderResult.UNDERFLOW) {
581
            if(coderResult == CoderResult.UNDERFLOW) {
601
                endOfInput = source.readNext();
582
                endOfInput = source.readNext();
Lines 603-609 Link Here
603
            while((coderResult =
584
            while((coderResult =
604
                    decoder.decode(source.buffer, out, endOfInput))
585
                    decoder.decode(source.buffer, out, endOfInput))
605
                    != CoderResult.UNDERFLOW) {
586
                    != CoderResult.UNDERFLOW) {
606
                out = buffer.growBuffer();
587
                out = buffer.growBuffer();                
607
            }
588
            }
608
            if(endOfInput) {
589
            if(endOfInput) {
609
                while((coderResult = decoder.flush(out))
590
                while((coderResult = decoder.flush(out))
Lines 676-682 Link Here
676
                return c;
657
                return c;
677
            }
658
            }
678
659
679
            private void reset() {
660
            private void reset() {               
680
                scope.reset();
661
                scope.reset();
681
                charBuffer.clear();
662
                charBuffer.clear();
682
            }
663
            }
Lines 690-699 Link Here
690
                return charBuffer;
671
                return charBuffer;
691
            }
672
            }
692
673
693
            private void adjustScope() {
674
            private void adjustScope() {             
694
                scope.start = scope.end == -1 ? 0 : scope.end;
675
                scope.start = scope.end == -1 ? 0 : scope.end;              
695
                flip();
676
                flip();                                                 
696
                scope.end = scope.start + charBuffer.limit();
677
                scope.end = scope.start + charBuffer.limit();                              
697
            }
678
            }
698
679
699
            /**
680
            /**
(-)a/utilities/src/org/netbeans/modules/search/ContextView.java (-1 / +1 lines)
Lines 313-319 Link Here
313
                                            = matchingObj.checkValidity();
313
                                            = matchingObj.checkValidity();
314
            if (invalidityStatus != null) {
314
            if (invalidityStatus != null) {
315
                displayMessage(invalidityStatus.getDescription(
315
                displayMessage(invalidityStatus.getDescription(
316
                                            matchingObj.getFile().getPath()));
316
                                            matchingObj.getFileObject().getPath()));
317
                return;
317
                return;
318
            }
318
            }
319
            
319
            
(-)a/utilities/src/org/netbeans/modules/search/MatchingObject.java (-53 / +39 lines)
Lines 44-55 Link Here
44
44
45
package org.netbeans.modules.search;
45
package org.netbeans.modules.search;
46
46
47
import org.openide.util.Exceptions;
48
import java.awt.EventQueue;
47
import java.awt.EventQueue;
49
import java.beans.PropertyChangeEvent;
48
import java.beans.PropertyChangeEvent;
50
import java.beans.PropertyChangeListener;
49
import java.beans.PropertyChangeListener;
51
import java.io.File;
52
import java.io.FileInputStream;
53
import java.io.IOException;
50
import java.io.IOException;
54
import java.io.OutputStreamWriter;
51
import java.io.OutputStreamWriter;
55
import java.io.Writer;
52
import java.io.Writer;
Lines 61-67 Link Here
61
import java.util.regex.Matcher;
58
import java.util.regex.Matcher;
62
import org.openide.filesystems.FileLock;
59
import org.openide.filesystems.FileLock;
63
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileUtil;
65
import org.openide.loaders.DataObject;
61
import org.openide.loaders.DataObject;
66
import org.openide.util.NbBundle;
62
import org.openide.util.NbBundle;
67
import static java.util.logging.Level.FINER;
63
import static java.util.logging.Level.FINER;
Lines 84-90 Link Here
84
    /** */
80
    /** */
85
    private final ResultModel resultModel;
81
    private final ResultModel resultModel;
86
    /** */
82
    /** */
87
    private final File file;
83
    private final FileObject fileObject;
88
    /** */
84
    /** */
89
    private final long timestamp;
85
    private final long timestamp;
90
    
86
    
Lines 137-143 Link Here
137
    /** */
133
    /** */
138
    private boolean valid = true;
134
    private boolean valid = true;
139
    /** */
135
    /** */
140
    private StringBuilder text;
136
    private String text;
141
    
137
    
142
    /**
138
    /**
143
     * Creates a new {@code MatchingObject} with a reference to the found
139
     * Creates a new {@code MatchingObject} with a reference to the found
Lines 162-170 Link Here
162
        this.object = object;
158
        this.object = object;
163
        this.charset = charset;
159
        this.charset = charset;
164
        
160
        
165
        FileObject fileObject = getFileObject();
161
        fileObject = fileObject();
166
        file = FileUtil.toFile(fileObject);
162
        timestamp =  fileObject.lastModified().getTime();        
167
        timestamp = (file != null) ? file.lastModified() : 0L;
168
        valid = (timestamp != 0L);
163
        valid = (timestamp != 0L);
169
        
164
        
170
        setUpDataObjValidityChecking();
165
        setUpDataObjValidityChecking();
Lines 213-223 Link Here
213
        return valid && data != null ? data.isValid() : false; // #190819
208
        return valid && data != null ? data.isValid() : false; // #190819
214
    }
209
    }
215
    
210
    
216
    FileObject getFileObject() {
211
    private FileObject fileObject() {
217
        return object instanceof FileObject ?
212
        return object instanceof FileObject ?
218
            (FileObject) object :
213
            (FileObject) object :
219
            ((DataObject) getDataObject()).getPrimaryFile();
214
            ((DataObject) getDataObject()).getPrimaryFile();
220
    }
215
    }
216
217
    /**
218
     */
219
    FileObject getFileObject() {
220
        return fileObject;
221
    }
221
    
222
    
222
    /**
223
    /**
223
     */
224
     */
Lines 378-392 Link Here
378
        return expanded;
379
        return expanded;
379
    }
380
    }
380
    
381
    
381
    /**
382
     */
383
    File getFile() {
384
        return file;
385
    }
386
    
382
    
387
    /** Get the name (not the path) of the file */
383
    /** Get the name (not the path) of the file */
388
    String getName() {
384
    String getName() {        
389
        return getFile().getName();
385
        return getFileObject().getName();
390
    }
386
    }
391
387
392
    String getHtmlDisplayName() {
388
    String getHtmlDisplayName() {
Lines 410-428 Link Here
410
    
406
    
411
    /**
407
    /**
412
     */
408
     */
413
    String getDescription() {
409
    String getDescription() { 
414
        return getFile().getParent();
410
        return getFileObject().getParent().getPath();
415
    }
411
    }
416
412
417
    /**
413
    /**
418
     */
414
     */
419
    String getText() throws IOException {
415
    String getText() throws IOException {
420
        StringBuilder txt = text();
416
        return text(false);
421
        if (txt != null) {
422
            return txt.toString();
423
        } else {
424
            return null;
425
        }
426
    }
417
    }
427
418
428
    /**
419
    /**
Lines 437-453 Link Here
437
     * @author  TimBoudreau
428
     * @author  TimBoudreau
438
     * @author  Marian Petras
429
     * @author  Marian Petras
439
     */
430
     */
440
    private StringBuilder text() throws IOException {
431
 
441
        return text(false);
432
    private String text(boolean refreshCache) throws IOException {
442
    }
443
    
444
    private StringBuilder text(boolean refreshCache) throws IOException {
445
        assert !EventQueue.isDispatchThread();
433
        assert !EventQueue.isDispatchThread();
446
        
434
        
447
        if (refreshCache || (text == null)) {
435
        if (refreshCache || (text == null)) {     
448
            text = new StringBuilder(Utils.getCharSequence(new FileInputStream(getFile()), charset));
436
            text = getFileObject().asText();
449
        }
437
        }
450
        return text == null ? new StringBuilder() : text;
438
        return text;
451
    }
439
    }
452
440
453
    @Override
441
    @Override
Lines 470-476 Link Here
470
            }
458
            }
471
            throw new IOException("Unknown object in search: " +
459
            throw new IOException("Unknown object in search: " +
472
                                  object);// NOI18N
460
                                  object);// NOI18N
473
        } catch (IOException ex) {
461
        } catch (IOException ex) {       
474
            valid = false;
462
            valid = false;
475
            return null;
463
            return null;
476
        }
464
        }
Lines 549-555 Link Here
549
        
537
        
550
        InvalidityStatus status = getInvalidityStatus();
538
        InvalidityStatus status = getInvalidityStatus();
551
        if (status != null) {
539
        if (status != null) {
552
            descr = status.getDescription(getFile().getPath());
540
            descr = status.getDescription(getFileObject().getPath());
553
        } else {
541
        } else {
554
            descr = null;
542
            descr = null;
555
        }
543
        }
Lines 566-583 Link Here
566
     */
554
     */
567
    private InvalidityStatus getInvalidityStatus() {
555
    private InvalidityStatus getInvalidityStatus() {
568
        log(FINER, "getInvalidityStatus()");                            //NOI18N
556
        log(FINER, "getInvalidityStatus()");                            //NOI18N
569
        File f = getFile();
557
        FileObject f = getFileObject();
570
        if (!f.exists()) {
558
        if (!f.isValid()) {
571
            log(FINEST, " - DELETED");
559
            log(FINEST, " - DELETED");            
572
            return InvalidityStatus.DELETED;
560
            return InvalidityStatus.DELETED;
573
        }
561
        }
574
        
562
        if (f.isFolder()) {
575
        if (f.isDirectory()) {
563
            log(FINEST, " - BECAME_DIR");            
576
            log(FINEST, " - BECAME_DIR");
577
            return InvalidityStatus.BECAME_DIR;
564
            return InvalidityStatus.BECAME_DIR;
578
        }
565
        }
579
        
566
        
580
        long stamp = f.lastModified();
567
        long stamp = f.lastModified().getTime();
581
        if (stamp > resultModel.getCreationTime()) {
568
        if (stamp > resultModel.getCreationTime()) {
582
            log(SEVERE, "file's timestamp changed since start of the search");
569
            log(SEVERE, "file's timestamp changed since start of the search");
583
            if (LOG.isLoggable(FINEST)) {
570
            if (LOG.isLoggable(FINEST)) {
Lines 586-600 Link Here
586
                log(FINEST, " - file stamp:           " + stamp + " (" + cal.getTime() + ')');
573
                log(FINEST, " - file stamp:           " + stamp + " (" + cal.getTime() + ')');
587
                cal.setTimeInMillis(resultModel.getCreationTime());
574
                cal.setTimeInMillis(resultModel.getCreationTime());
588
                log(FINEST, " - result model created: " + resultModel.getCreationTime() + " (" + cal.getTime() + ')');
575
                log(FINEST, " - result model created: " + resultModel.getCreationTime() + " (" + cal.getTime() + ')');
589
            }
576
            }            
590
            return InvalidityStatus.CHANGED;
577
            return InvalidityStatus.CHANGED;
591
        }
578
        }
592
        
579
        
593
        if (f.length() > Integer.MAX_VALUE) {
580
        if (f.getSize() > Integer.MAX_VALUE) {            
594
            return InvalidityStatus.TOO_BIG;
581
            return InvalidityStatus.TOO_BIG;
595
        }
582
        }
596
        
583
        
597
        if (!f.canRead()) {
584
        if (!f.canRead()) {           
598
            return InvalidityStatus.CANT_READ;
585
            return InvalidityStatus.CANT_READ;
599
        }
586
        }
600
        
587
        
Lines 619-626 Link Here
619
        if (shouldReplaceNone) {
606
        if (shouldReplaceNone) {
620
            return null;
607
            return null;
621
        }
608
        }
622
        
609
       
623
        StringBuilder content = text(true);   //refresh the cache, reads the file
610
        StringBuilder content = new StringBuilder(text(true));   //refresh the cache, reads the file
624
        
611
        
625
        List<TextDetail> textMatches = 
612
        List<TextDetail> textMatches = 
626
                resultModel.basicCriteria.getTextDetails(getFileObject());
613
                resultModel.basicCriteria.getTextDetails(getFileObject());
Lines 667-674 Link Here
667
            throw new IllegalStateException("Buffer is gone");          //NOI18N
654
            throw new IllegalStateException("Buffer is gone");          //NOI18N
668
        }
655
        }
669
        
656
        
670
        if (REALLY_WRITE) {
657
        if (REALLY_WRITE) {            
671
            final FileObject fileObject = getFileObject();
672
            Writer writer = null;
658
            Writer writer = null;
673
            try {
659
            try {
674
                writer = new OutputStreamWriter(
660
                writer = new OutputStreamWriter(
Lines 681-687 Link Here
681
                }
667
                }
682
            }
668
            }
683
        } else {
669
        } else {
684
            System.err.println("Would write to " + getFile().getPath());//NOI18N
670
            System.err.println("Would write to " + getFileObject().getPath());//NOI18N
685
            System.err.println(text);
671
            System.err.println(text);
686
        }
672
        }
687
    }
673
    }
Lines 689-695 Link Here
689
    /**
675
    /**
690
     */
676
     */
691
    private String makeStringToWrite() {
677
    private String makeStringToWrite() {
692
        return makeStringToWrite(text);
678
        return text;
693
    }
679
    }
694
    
680
    
695
    /**
681
    /**
Lines 726-732 Link Here
726
            return false;
712
            return false;
727
        }
713
        }
728
        final MatchingObject other = (MatchingObject) obj;
714
        final MatchingObject other = (MatchingObject) obj;
729
        if (this.file != other.file && (this.file == null || !this.file.equals(other.file))) {
715
        if (this.fileObject != other.fileObject && (this.fileObject == null || !this.fileObject.equals(other.fileObject))) {
730
            return false;
716
            return false;
731
        }
717
        }
732
        return true;
718
        return true;
Lines 735-741 Link Here
735
    @Override
721
    @Override
736
    public int hashCode() {
722
    public int hashCode() {
737
        int hash = 3;
723
        int hash = 3;
738
        hash = 73 * hash + (this.file != null ? this.file.hashCode() : 0);
724
        hash = 73 * hash + (this.fileObject != null ? this.fileObject.hashCode() : 0);
739
        return hash;
725
        return hash;
740
    }
726
    }
741
727
(-)a/utilities/src/org/netbeans/modules/search/NodeListener.java (-1 / +7 lines)
Lines 56-61 Link Here
56
import java.awt.event.KeyListener;
56
import java.awt.event.KeyListener;
57
import java.awt.event.MouseEvent;
57
import java.awt.event.MouseEvent;
58
import java.awt.event.MouseListener;
58
import java.awt.event.MouseListener;
59
import java.io.File;
59
import java.io.IOException;
60
import java.io.IOException;
60
import java.util.ArrayList;
61
import java.util.ArrayList;
61
import java.util.Collection;
62
import java.util.Collection;
Lines 75-80 Link Here
75
import javax.swing.tree.TreeSelectionModel;
76
import javax.swing.tree.TreeSelectionModel;
76
import org.openide.actions.EditAction;
77
import org.openide.actions.EditAction;
77
import org.openide.cookies.EditCookie;
78
import org.openide.cookies.EditCookie;
79
import org.openide.filesystems.FileObject;
80
import org.openide.filesystems.FileUtil;
78
import org.openide.nodes.Node;
81
import org.openide.nodes.Node;
79
import org.openide.util.NbBundle;
82
import org.openide.util.NbBundle;
80
import org.openide.util.SharedClassObject;
83
import org.openide.util.SharedClassObject;
Lines 629-635 Link Here
629
    private CopyTextAction newCopyTextAction(TreePath path) {
632
    private CopyTextAction newCopyTextAction(TreePath path) {
630
        try {
633
        try {
631
            MatchingObject mo = getMatchingObject(path);
634
            MatchingObject mo = getMatchingObject(path);
632
            String filePath = mo.getFile().getCanonicalPath(); // NPE, IOE
635
636
            FileObject fileObject = mo.getFileObject();
637
            File file = FileUtil.toFile(fileObject);
638
            String filePath = ( file != null )?  file.getCanonicalPath() :  fileObject.getPath();
633
            String ctaName = NbBundle.getBundle(this.getClass()).
639
            String ctaName = NbBundle.getBundle(this.getClass()).
634
                                  getString("LBL_CopyFilePathAction"); // NOI18N
640
                                  getString("LBL_CopyFilePathAction"); // NOI18N
635
            CopyTextAction cta = new CopyTextAction(ctaName);
641
            CopyTextAction cta = new CopyTextAction(ctaName);
(-)a/utilities/src/org/netbeans/modules/search/ReplaceTask.java (-2 / +2 lines)
Lines 135-141 Link Here
135
        for(MatchingObject mo: matchingObjects) {
135
        for(MatchingObject mo: matchingObjects) {
136
            InvalidityStatus status = mo.checkValidity();
136
            InvalidityStatus status = mo.checkValidity();
137
            if (status != null) {
137
            if (status != null) {
138
                problems.add(status.getDescription(mo.getFile().getPath()));
138
                problems.add(status.getDescription(mo.getFileObject().getPath()));
139
                if (++errorsCount > MAX_ERRORS_CHECKED) {
139
                if (++errorsCount > MAX_ERRORS_CHECKED) {
140
                    break;
140
                    break;
141
                }
141
                }
Lines 177-183 Link Here
177
                if (status == null) {
177
                if (status == null) {
178
                    obj.write(fileLock);
178
                    obj.write(fileLock);
179
                } else {
179
                } else {
180
                    errMessage = status.getDescription(obj.getFile().getPath());
180
                    errMessage = status.getDescription(obj.getFileObject().getPath());
181
                }
181
                }
182
            } catch (FileAlreadyLockedException ex) {
182
            } catch (FileAlreadyLockedException ex) {
183
                errMessage = createMsgFileLocked(obj);
183
                errMessage = createMsgFileLocked(obj);
(-)a/utilities/src/org/netbeans/modules/search/TextFetcher.java (-4 / +3 lines)
Lines 100-107 Link Here
100
                return;
100
                return;
101
            }
101
            }
102
            
102
            
103
            FileObject fob = FileUtil.toFileObject(
103
            FileObject fob = source.matchingObj.getFileObject(); 
104
                                                source.matchingObj.getFile());
105
            String mimeType = fob.getMIMEType();
104
            String mimeType = fob.getMIMEType();
106
            //We don't want the swing html editor kit, and even if we 
105
            //We don't want the swing html editor kit, and even if we 
107
            //do get it, it will frequently throw a random NPE 
106
            //do get it, it will frequently throw a random NPE 
Lines 166-173 Link Here
166
            return false;
165
            return false;
167
        }
166
        }
168
        
167
        
169
        boolean result = source.matchingObj.getFile()
168
        boolean result = source.matchingObj.getFileObject()
170
                         .equals(item.matchingObj.getFile());
169
                         .equals(item.matchingObj.getFileObject());
171
        if (result) {
170
        if (result) {
172
            setLocation(item.getLocation());
171
            setLocation(item.getLocation());
173
            task.schedule(50);
172
            task.schedule(50);

Return to bug 194326