question: protected void indexPolygons ( InputStream is , long ptr , OutputStream os ) { boolean moreRecords = true ; byte rHdr [ ] = new byte [ SHAPE_RECORD_HEADER_LENGTH ] ; byte outBuf [ ] = new byte [ SPATIAL_INDEX_RECORD_LENGTH ] ; int result ; int shapeType ; int nRecords = 0 ; int recLengthWords , recLengthBytes ; long recOffset ; int recBufSize = 100000 ; byte recBuf [ ] = new byte [ recBufSize ] ; ESRIBoundingBox polyBounds ; try { while ( moreRecords ) { result = is . read ( rHdr , 0 , SHAPE_RECORD_HEADER_LENGTH ) ; if ( result < 0 ) { moreRecords = false ; if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "Found " + nRecords + " records" ) ; logger . fine ( "recBufSize = " + recBufSize ) ; } } else { nRecords ++ ; recOffset = ptr ; readBEInt ( rHdr , 0 ) ; recLengthWords = readBEInt ( rHdr , 4 ) ; recLengthBytes = recLengthWords * 2 ; if ( recLengthBytes > recBufSize ) { if ( logger . isLoggable ( Level . FINE ) ) { logger . fine ( "Shapefile SpatialIndex increasing recBufSize to " + recLengthBytes ) ; } recBufSize = recLengthBytes ; recBuf = new byte [ recBufSize ] ; } result = is . read ( recBuf , 0 , recLengthBytes ) ; shapeType = readLEInt ( recBuf , 0 ) ; if ( shapeType != SHAPE_TYPE_NULL ) { polyBounds = readBox ( recBuf , 4 ) ; } else { polyBounds = new ESRIBoundingBox ( ) ; } ptr += recLengthBytes + 8 ; writeBEInt ( outBuf , 0 , ( int ) ( recOffset / 2 ) ) ; writeBEInt ( outBuf , 4 , recLengthWords ) ; writeLEDouble ( outBuf , 8 , polyBounds . min . x ) ; writeLEDouble ( outBuf , 16 , polyBounds . min . y ) ; writeLEDouble ( outBuf , 24 , polyBounds . max . x ) ; writeLEDouble ( outBuf , 32 , polyBounds . max . y ) ; os . write ( outBuf , 0 , SPATIAL_INDEX_RECORD_LENGTH ) ; } } } catch ( java . io . IOException e ) { e . printStackTrace ( ) ; } finally { try { is . close ( ) ; } catch ( java . io . IOException e ) { } } }
target:  Writes the spatial index for a polygon shape file.