Revision 47643 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/gml/virtualrows/XMLFileAsList.java
XMLFileAsList.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.fmap.dal.store.gml.virtualrows; |
7 | 7 |
|
8 |
import org.gvsig.fmap.dal.store.simplereader.virtualrows.LimitedReader; |
|
8 | 9 |
import java.io.BufferedReader; |
9 | 10 |
import java.io.Closeable; |
10 | 11 |
import java.io.File; |
... | ... | |
188 | 189 |
} |
189 | 190 |
} |
190 | 191 |
|
191 |
System.out.println("RECORD "+position); |
|
192 |
// System.out.println("RECORD "+position);
|
|
192 | 193 |
ParseRecordsHandler handler = null; |
193 | 194 |
Record record = this.index.get64(position); |
194 | 195 |
try { |
195 | 196 |
long recordPosition = record.getLong(IDXFIELD_BEGINRECORDPOS); |
196 | 197 |
this.reader.seek(recordPosition); |
197 |
BufferedReader breader = new BufferedReader(this.reader, 1024 * 8); |
|
198 |
// TODO: guardarse el tama?o del registro en el indice y en funcion de eso usar un buffersize mas peque?o aqui si procede |
|
199 |
int bufferSize = 1024*8; |
|
200 |
BufferedReader breader = new BufferedReader(this.reader, bufferSize); |
|
198 | 201 |
|
199 | 202 |
InputSource is = new InputSource(CloseShieldReader.wrap(breader)); |
200 | 203 |
SAXParserFactory spf = SAXParserFactory.newInstance(); |
... | ... | |
202 | 205 |
SAXParser saxParser = spf.newSAXParser(); |
203 | 206 |
handler = new ParseRecordsHandler(); |
204 | 207 |
handler.endLineNumber=(int) (record.getLong(IDXFIELD_ENDLINE)-record.getLong(IDXFIELD_BEGINLINE)+1); |
205 |
// if(record.getLong(IDXFIELD_ENDLINE)==record.getLong(IDXFIELD_BEGINLINE)){ |
|
206 |
// handler.endColumnNumber=(int) (record.getLong(IDXFIELD_ENDCOLUMN)-record.getLong(IDXFIELD_BEGINCOLUMN)); |
|
207 |
// } else { |
|
208 |
handler.endColumnNumber=(int) record.getLong(IDXFIELD_ENDCOLUMN); |
|
209 |
// } |
|
208 |
handler.endColumnNumber=(int) record.getLong(IDXFIELD_ENDCOLUMN); |
|
210 | 209 |
|
211 | 210 |
saxParser.parse(is, handler); |
212 | 211 |
} catch (StopParserSAXException ex) { |
... | ... | |
233 | 232 |
if(position == 0){ |
234 | 233 |
char[] cbuff = new char[(int)(endGeomPosition-geomPosition)]; |
235 | 234 |
this.reader.read(cbuff); |
236 |
System.out.println("["+new String(cbuff)+"]"); |
|
235 |
// System.out.println("["+new String(cbuff)+"]");
|
|
237 | 236 |
this.reader.seek(geomPosition); |
238 | 237 |
} |
239 | 238 |
Reader limitedReader = new LimitedReader(reader, (int)(endGeomPosition-geomPosition)); |
240 |
BufferedReader breader = new BufferedReader(limitedReader, 1024 * 8); |
|
239 |
// TODO: calcular el buffersize como el min(8k,endGeomPosition-geomPosition+1) |
|
240 |
int bufferSize = 1024*8; |
|
241 |
BufferedReader breader = new BufferedReader(limitedReader, bufferSize); |
|
241 | 242 |
geom = GeometryLocator.getGeometryManager().createFrom(breader, null); |
242 | 243 |
if(this.combineMode == COMBINE_FIRST_NOT_NULL){ |
243 | 244 |
if(geom != null){ |
... | ... | |
291 | 292 |
try { |
292 | 293 |
// 1. Creamos el indice vacio |
293 | 294 |
RecordsFile.RecordTypeBuilder builder = recordTypeBuilder() |
295 |
.addInteger() |
|
296 |
.addInteger() |
|
294 | 297 |
.addLong() |
295 |
.addLong() |
|
296 |
.addLong() |
|
297 |
.addLong() |
|
298 |
.addLong(); |
|
298 |
.addInteger() |
|
299 |
.addInteger(); |
|
299 | 300 |
|
300 | 301 |
if (CollectionUtils.isNotEmpty(geomPaths)) { |
301 |
for (String geomPath : geomPaths) { |
|
302 |
builder.addLong() |
|
302 |
for (int i = 0; i < geomPaths.size(); i++) { |
|
303 |
builder.addInteger() |
|
304 |
.addInteger() |
|
303 | 305 |
.addLong() |
304 |
.addLong() |
|
305 |
.addLong() |
|
306 |
.addLong() |
|
306 |
.addInteger() |
|
307 |
.addInteger() |
|
307 | 308 |
.addLong(); |
308 | 309 |
} |
309 | 310 |
} |
... | ... | |
414 | 415 |
for (int j = 0; j < theIndex.size(); j++) { |
415 | 416 |
Record r = theIndex.get(j); |
416 | 417 |
// if(i==0){ |
417 |
System.out.println("RECO BEGIN: "+r.getLong(IDXFIELD_BEGINLINE) + " " + r.getLong(IDXFIELD_BEGINCOLUMN)); |
|
418 |
if(CollectionUtils.isNotEmpty(geomPaths)) { |
|
419 |
for (int i = 0; i < geomPaths.size(); i++) { |
|
420 |
System.out.println("GEOM"+i+"BEGIN: "+r.getLong(IDXFIELD_BEGINGEOMLINE+i*6) + " " + r.getLong(IDXFIELD_BEGINGEOMCOLUMN+i*6)); |
|
421 |
System.out.println("GEOM"+i+"END : "+r.getLong(IDXFIELD_ENDGEOMLINE+i*6) + " " + r.getLong(IDXFIELD_ENDGEOMCOLUMN+i*6)); |
|
422 |
} |
|
423 |
} |
|
424 |
System.out.println("RECO END : "+r.getLong(IDXFIELD_ENDLINE) + " " + r.getLong(IDXFIELD_ENDCOLUMN)); |
|
418 |
// System.out.println("RECO BEGIN: "+r.getLong(IDXFIELD_BEGINLINE) + " " + r.getLong(IDXFIELD_BEGINCOLUMN));
|
|
419 |
// if(CollectionUtils.isNotEmpty(geomPaths)) {
|
|
420 |
// for (int i = 0; i < geomPaths.size(); i++) {
|
|
421 |
// System.out.println("GEOM"+i+"BEGIN: "+r.getLong(IDXFIELD_BEGINGEOMLINE+i*6) + " " + r.getLong(IDXFIELD_BEGINGEOMCOLUMN+i*6));
|
|
422 |
// System.out.println("GEOM"+i+"END : "+r.getLong(IDXFIELD_ENDGEOMLINE+i*6) + " " + r.getLong(IDXFIELD_ENDGEOMCOLUMN+i*6));
|
|
423 |
// }
|
|
424 |
// }
|
|
425 |
// System.out.println("RECO END : "+r.getLong(IDXFIELD_ENDLINE) + " " + r.getLong(IDXFIELD_ENDCOLUMN));
|
|
425 | 426 |
// } |
426 | 427 |
positionCalculator.next(r.getLong(IDXFIELD_BEGINLINE), r.getLong(IDXFIELD_BEGINCOLUMN)); |
427 | 428 |
r.setLong(IDXFIELD_BEGINRECORDPOS, positionCalculator.getColumnPosition()); |
428 |
System.out.println("RPOS : " + r.getLong(IDXFIELD_BEGINRECORDPOS)); |
|
429 |
// System.out.println("RPOS : " + r.getLong(IDXFIELD_BEGINRECORDPOS));
|
|
429 | 430 |
if(CollectionUtils.isNotEmpty(geomPaths)) { |
430 | 431 |
for (int i = 0; i < geomPaths.size(); i++) { |
431 | 432 |
long beginGeomLine = r.getLong(IDXFIELD_BEGINGEOMLINE + i * 6); |
... | ... | |
437 | 438 |
r.setLong(IDXFIELD_BEGINGEOMPOS + i * 6, positionCalculator.getColumnPosition()); |
438 | 439 |
positionCalculator.next(endGeomLine, r.getLong(IDXFIELD_ENDGEOMCOLUMN + i * 6)); |
439 | 440 |
r.setLong(IDXFIELD_ENDGEOMPOS + i * 6, positionCalculator.getColumnPosition()); |
440 |
System.out.println("GPOS" + i + " : " + r.getLong(IDXFIELD_BEGINGEOMPOS + i * 6) + " " + r.getLong(IDXFIELD_ENDGEOMPOS + i * 6)); |
|
441 |
// System.out.println("GPOS" + i + " : " + r.getLong(IDXFIELD_BEGINGEOMPOS + i * 6) + " " + r.getLong(IDXFIELD_ENDGEOMPOS + i * 6));
|
|
441 | 442 |
} |
442 | 443 |
} |
443 | 444 |
theIndex.set(j, r); |
444 |
// if(i==0){ |
|
445 |
// } |
|
446 | 445 |
} |
447 | 446 |
this.index = new RecordsFileImpl(indexFile); |
448 | 447 |
} catch (Exception ex) { |
... | ... | |
450 | 449 |
} |
451 | 450 |
} |
452 | 451 |
|
453 |
private static class LimitedReader extends Reader { |
|
454 | 452 |
|
455 |
private final Reader delegated; |
|
456 |
private final int limit; |
|
457 |
private int count; |
|
458 |
|
|
459 |
public LimitedReader(Reader reader, int limit) { |
|
460 |
this.delegated = reader; |
|
461 |
this.limit = limit; |
|
462 |
} |
|
463 |
|
|
464 |
@Override |
|
465 |
public int read(char[] cbuf, int off, int len) throws IOException { |
|
466 |
if(count >= limit){ |
|
467 |
return -1; |
|
468 |
} |
|
469 |
if(count+len > limit){ |
|
470 |
len = limit - count; |
|
471 |
} |
|
472 |
if(len==0){ |
|
473 |
return -1; |
|
474 |
} |
|
475 |
int n = this.delegated.read(cbuf, off, len); |
|
476 |
if(count+n <= limit){ |
|
477 |
count += n; |
|
478 |
return n; |
|
479 |
} |
|
480 |
return limit - count; |
|
481 |
|
|
482 |
} |
|
483 |
|
|
484 |
@Override |
|
485 |
public void close() throws IOException { |
|
486 |
// this.delegated.close(); |
|
487 |
} |
|
488 |
|
|
489 |
@Override |
|
490 |
public int read(java.nio.CharBuffer target) throws IOException { |
|
491 |
return this.delegated.read(target); |
|
492 |
} |
|
493 |
|
|
494 |
@Override |
|
495 |
public int read() throws IOException { |
|
496 |
return this.delegated.read(); |
|
497 |
} |
|
498 |
|
|
499 |
@Override |
|
500 |
public int read(char cbuf[]) throws IOException { |
|
501 |
return this.delegated.read(cbuf); |
|
502 |
} |
|
503 |
|
|
504 |
@Override |
|
505 |
public long skip(long n) throws IOException { |
|
506 |
return this.delegated.skip(n); |
|
507 |
} |
|
508 |
|
|
509 |
@Override |
|
510 |
public boolean ready() throws IOException { |
|
511 |
return this.delegated.ready(); |
|
512 |
} |
|
513 |
|
|
514 |
@Override |
|
515 |
public boolean markSupported() { |
|
516 |
return this.delegated.markSupported(); |
|
517 |
} |
|
518 |
|
|
519 |
@Override |
|
520 |
public void mark(int readAheadLimit) throws IOException { |
|
521 |
this.delegated.mark(readAheadLimit); |
|
522 |
} |
|
523 |
|
|
524 |
@Override |
|
525 |
public void reset() throws IOException { |
|
526 |
this.delegated.reset(); |
|
527 |
} |
|
528 |
} |
|
529 |
|
|
530 | 453 |
private static class CharacterSize { |
531 | 454 |
|
532 | 455 |
private final Charset charset; |
... | ... | |
587 | 510 |
} |
588 | 511 |
|
589 | 512 |
public boolean next(long line, long column) throws IOException { |
590 |
System.out.println(); |
|
591 |
System.out.println("----"+line+" "+column); |
|
513 |
// System.out.println();
|
|
514 |
// System.out.println("----"+line+" "+column);
|
|
592 | 515 |
if(this.currentLine>line){ |
593 | 516 |
throw new IOException("Illegal column number " + column + " ("+this.currentColumn+") for line " + line+ " ("+this.currentLine+")"); |
594 | 517 |
} |
595 | 518 |
if(this.currentLine==line && this.currentColumn > column){ |
596 | 519 |
throw new IOException("Illegal column number " + column + " ("+this.currentColumn+") for line " + line); |
597 | 520 |
} |
598 |
System.out.print(this.currentLine+":"); |
|
521 |
// System.out.print(this.currentLine+":");
|
|
599 | 522 |
while (this.currentLine < line) { |
600 | 523 |
if (breader.read(this.ch, 0, 1) < 1) { |
601 | 524 |
return false; |
602 | 525 |
} |
603 | 526 |
char c = ch[0]; |
604 |
System.out.print(String.valueOf(c)); |
|
527 |
// System.out.print(String.valueOf(c));
|
|
605 | 528 |
this.currentPosition += characterSize.size(c); |
606 | 529 |
if (c == '\n') { |
607 | 530 |
this.currentLine++; |
608 | 531 |
this.currentColumn = 1; |
609 |
System.out.print(this.currentLine+":"); |
|
532 |
// System.out.print(this.currentLine+":");
|
|
610 | 533 |
} |
611 | 534 |
} |
612 | 535 |
this.currentLinePosition = this.currentPosition; |
613 |
while (true) { //this.currentColumn < column) {
|
|
536 |
while (true) { |
|
614 | 537 |
if (breader.read(this.ch, 0, 1) < 1) { |
615 | 538 |
return false; |
616 | 539 |
} |
617 | 540 |
char c = ch[0]; |
618 |
System.out.print(String.valueOf(c)); |
|
541 |
// System.out.print(String.valueOf(c));
|
|
619 | 542 |
this.currentColumn++; |
620 | 543 |
this.currentPosition += characterSize.size(c); |
621 | 544 |
if(this.currentColumn >= column){ |
622 | 545 |
break; |
623 | 546 |
} |
624 | 547 |
if (c == '\n') { |
625 |
// if (this.currentColumn < column) { |
|
626 |
// Uff, esto seria un error, ya que la linea corriente no |
|
627 |
// tiene tantas columnas. |
|
628 |
throw new IOException("Illegal column number " + column + " ("+this.currentColumn+") for line " + line+ " ("+this.currentLine+")"); |
|
629 |
// } |
|
630 |
// this.currentLine++; |
|
548 |
throw new IOException("Illegal column number " + column + " ("+this.currentColumn+") for line " + line+ " ("+this.currentLine+")"); |
|
631 | 549 |
} |
632 | 550 |
} |
633 | 551 |
this.currentColumnPosition = this.currentPosition; |
634 |
System.out.println(); |
|
552 |
// System.out.println();
|
|
635 | 553 |
return true; |
636 | 554 |
} |
637 | 555 |
|
Also available in: Unified diff