Input:
/ * <xsd : element name = datasetScan substitutionGroup = dataset > <xsd : complexType > <xsd : complexContent > <xsd : extension base = DatasetType > <xsd : sequence > <xsd : element ref = filter minOccurs = 0 maxOccurs = 1 / > <xsd : element ref = namer minOccurs = 0 maxOccurs = 1 / > <xsd : element ref = sort minOccurs = 0 maxOccurs = 1 / > <xsd : element ref = addLatest minOccurs = 0 maxOccurs = 1 / > <xsd : element ref = addProxies minOccurs = 0 maxOccurs = 1 / > <xsd : element name = addDatasetSize minOccurs = 0 maxOccurs = 1 / > <xsd : element ref = addTimeCoverage minOccurs = 0 maxOccurs = 1 / > < / xsd : sequence > [CODESPLIT] public DatasetScanConfig readDatasetScanConfig ( Element dsElem ) { DatasetScanConfig result = new DatasetScanConfig ( ) ; result . name = dsElem . getAttributeValue ( "name" ) ; result . path = StringUtil2 . trim ( dsElem . getAttributeValue ( "path" ) , ' ' ) ; if ( result . path == null ) { errlog . format ( "ERROR: must specify path attribute.%n" ) ; fatalError = true ; } String scanDir = dsElem . getAttributeValue ( "location" ) ; if ( scanDir == null ) { errlog . format ( "ERROR: must specify directory root in location attribute.%n" ) ; fatalError = true ; } else { result . scanDir = AliasTranslator . translateAlias ( scanDir ) ; File scanFile = new File ( result . scanDir ) ; if ( ! scanFile . exists ( ) ) { errlog . format ( "ERROR: directory %s does not exist%n" , result . scanDir ) ; fatalError = true ; } } result . restrictAccess = dsElem . getAttributeValue ( "restrictAccess" ) ; // look for ncml Element ncmlElem = dsElem . getChild ( "netcdf" , Catalog . defNS ) ; if ( ncmlElem != null ) { ncmlElem . detach ( ) ; result . ncmlElement = ncmlElem ; } // Read filter element Element filterElem = dsElem . getChild ( "filter" , Catalog . defNS ) ; result . filters = readDatasetScanFilter ( filterElem ) ; // Read namer element Element namerElem = dsElem . getChild ( "namer" , Catalog . defNS ) ; result . namers = readDatasetScanNamer ( namerElem ) ; // Read filesSort or sort element Element filesSortElem = dsElem . getChild ( "filesSort" , Catalog . defNS ) ; if ( filesSortElem != null ) result . isSortIncreasing = readFilesSort ( filesSortElem ) ; Element sorterElem = dsElem . getChild ( "sort" , Catalog . defNS ) ; if ( ! result . isSortIncreasing . isPresent ( ) && sorterElem != null ) result . isSortIncreasing = readSort ( sorterElem ) ; // Deal with latest String addLatestAttribute = dsElem . getAttributeValue ( "addLatest" ) ; Element addLatestElem = dsElem . getChild ( "addLatest" , Catalog . defNS ) ; // not in docs Element addProxiesElem = dsElem . getChild ( "addProxies" , Catalog . defNS ) ; result . addLatest = readDatasetScanAddProxies ( addProxiesElem , addLatestElem , addLatestAttribute ) ; /* Read addDatasetSize element.
    Element addDsSizeElem = dsElem.getChild("addDatasetSize", Catalog.defNS);
    if (addDsSizeElem != null) {                                               // docs: default true
      if (addDsSizeElem.getTextNormalize().equalsIgnoreCase("false"))
        result.addDatasetSize = false;
    } */ // Read addTimeCoverage element. Element addTimeCovElem = dsElem . getChild ( "addTimeCoverage" , Catalog . defNS ) ; if ( addTimeCovElem != null ) { result . addTimeCoverage = readDatasetScanAddTimeCoverage ( addTimeCovElem ) ; } return result ; }


Input: / * <xsd : element name = filter > <xsd : complexType > <xsd : choice > <xsd : sequence minOccurs = 0 maxOccurs = unbounded > <xsd : element name = include type = FilterSelectorType minOccurs = 0 / > <xsd : element name = exclude type = FilterSelectorType minOccurs = 0 / > < / xsd : sequence > < / xsd : choice > < / xsd : complexType > < / xsd : element > [CODESPLIT] private List < DatasetScanConfig . Filter > readDatasetScanFilter ( Element filterElem ) { List < DatasetScanConfig . Filter > filters = new ArrayList <> ( ) ; if ( filterElem == null ) return null ; for ( Element curElem : filterElem . getChildren ( ) ) { String regExpAttVal = curElem . getAttributeValue ( "regExp" ) ; String wildcardAttVal = curElem . getAttributeValue ( "wildcard" ) ; String lastModLimitAttValS = curElem . getAttributeValue ( "lastModLimitInMillis" ) ; if ( regExpAttVal == null && wildcardAttVal == null && lastModLimitAttValS == null ) { // If no regExp or wildcard attributes, skip this selector. errlog . format ( "WARN: readDatasetScanFilter(): no regExp, wildcard, or lastModLimitInMillis attribute in filter child <%s>%n" , curElem . getName ( ) ) ; } else { // Determine if applies to atomic datasets, default true. String atomicAttVal = curElem . getAttributeValue ( "atomic" ) ; boolean atomic = ( atomicAttVal == null || ! atomicAttVal . equalsIgnoreCase ( "false" ) ) ; // Determine if applies to collection datasets, default false. String collectionAttVal = curElem . getAttributeValue ( "collection" ) ; boolean notCollection = collectionAttVal == null || ! collectionAttVal . equalsIgnoreCase ( "true" ) ; // Determine if include or exclude selectors. boolean includer = true ; if ( curElem . getName ( ) . equals ( "exclude" ) ) { includer = false ; } else if ( ! curElem . getName ( ) . equals ( "include" ) ) { errlog . format ( "WARN: readDatasetScanFilter(): unhandled filter child <%s>.%n" , curElem . getName ( ) ) ; continue ; } // check for errors long lastModLimitAttVal = - 1 ; if ( lastModLimitAttValS != null ) { try { lastModLimitAttVal = Long . parseLong ( lastModLimitAttValS ) ; } catch ( NumberFormatException e ) { errlog . format ( "WARN: readDatasetScanFilter(): lastModLimitInMillis not valid <%s>.%n" , curElem ) ; } } filters . add ( new DatasetScanConfig . Filter ( regExpAttVal , wildcardAttVal , lastModLimitAttVal , atomic , ! notCollection , includer ) ) ; } } return filters ; }


Input: / * <xsd : element name = namer > <xsd : complexType > <xsd : choice maxOccurs = unbounded > <xsd : element name = regExpOnName type = NamerSelectorType / > <xsd : element name = regExpOnPath type = NamerSelectorType / > < / xsd : choice > < / xsd : complexType > < / xsd : element > [CODESPLIT] protected List < DatasetScanConfig . Namer > readDatasetScanNamer ( Element namerElem ) { List < DatasetScanConfig . Namer > result = new ArrayList <> ( ) ; if ( namerElem == null ) return result ; for ( Element curElem : namerElem . getChildren ( ) ) { String regExp = curElem . getAttributeValue ( "regExp" ) ; String replaceString = curElem . getAttributeValue ( "replaceString" ) ; boolean onName = curElem . getName ( ) . equals ( "regExpOnName" ) ; boolean onPath = curElem . getName ( ) . equals ( "regExpOnPath" ) ; if ( ! onName && ! onPath ) { errlog . format ( "WARN: readDatasetScanNamer(): namer child '%s'%n" , curElem . getName ( ) ) ; continue ; } result . add ( new DatasetScanConfig . Namer ( onName , regExp , replaceString ) ) ; } return result ; }


Input: / * <xsd : element name = sort > <xsd : complexType > <xsd : choice > <xsd : element name = lexigraphicByName > <xsd : complexType > <xsd : attribute name = increasing type = xsd : boolean / > < / xsd : complexType > < / xsd : element > <xsd : element name = crawlableDatasetSorterImpl minOccurs = 0 type = UserImplType / > < / xsd : choice > < / xsd : complexType > < / xsd : element > [CODESPLIT] protected Optional < Boolean > readFilesSort ( Element sorterElem ) { String increasingString = sorterElem . getAttributeValue ( "increasing" ) ; if ( increasingString != null ) { if ( increasingString . equalsIgnoreCase ( "true" ) ) return Optional . of ( true ) ; else if ( increasingString . equalsIgnoreCase ( "false" ) ) return Optional . of ( false ) ; } return Optional . empty ( ) ; }


Input: / * <xsd : element name = addTimeCoverage > <xsd : complexType > <xsd : attribute name = datasetNameMatchPattern type = xsd : string / > <xsd : attribute name = datasetPathMatchPattern type = xsd : string / > <xsd : attribute name = startTimeSubstitutionPattern type = xsd : string / > <xsd : attribute name = duration type = xsd : string / > < / xsd : complexType > < / xsd : element > [CODESPLIT] protected DatasetScanConfig . AddTimeCoverage readDatasetScanAddTimeCoverage ( Element addTimeCovElem ) { String matchName = addTimeCovElem . getAttributeValue ( "datasetNameMatchPattern" ) ; String matchPath = addTimeCovElem . getAttributeValue ( "datasetPathMatchPattern" ) ; String subst = addTimeCovElem . getAttributeValue ( "startTimeSubstitutionPattern" ) ; String duration = addTimeCovElem . getAttributeValue ( "duration" ) ; boolean err = false ; if ( subst == null ) { errlog . format ( "WARN: readDatasetScanAddTimeCoverage(): must have startTimeSubstitutionPattern elem=<%s>%n" , addTimeCovElem ) ; err = true ; } else if ( duration == null ) { errlog . format ( "WARN: readDatasetScanAddTimeCoverage(): must have duration elem=<%s>%n" , addTimeCovElem ) ; err = true ; } else if ( matchName == null && matchPath == null ) { errlog . format ( "WARN: readDatasetScanAddTimeCoverage(): must have either datasetNameMatchPattern or datasetPathMatchPattern elem=<%s>%n" , addTimeCovElem ) ; err = true ; } return err ? null : new DatasetScanConfig . AddTimeCoverage ( matchName , matchPath , subst , duration ) ; }


Input: all CdmrFeatureDatasets must return their featureType - use as a fail - fast test of the endpoint [CODESPLIT] public static FeatureType isCdmrfEndpoint ( String endpoint ) throws IOException { HTTPSession httpClient = HTTPFactory . newSession ( endpoint ) ; String url = endpoint + "?req=featureType" ; // get the header try ( HTTPMethod method = HTTPFactory . Get ( httpClient , url ) ) { method . setFollowRedirects ( true ) ; int statusCode = method . execute ( ) ; if ( statusCode != 200 ) return null ; String content = method . getResponseAsString ( ) ; return FeatureType . getType ( content ) ; } catch ( Throwable t ) { t . printStackTrace ( ) ; return null ; } }


Input: Set the value type of the option switch to the type passed [CODESPLIT] public void SetHasValue ( int type ) { this . type = type ; if ( debug ) { System . out . println ( "sw = " + ( char ) sw + "; type = " + type + "; set = " + set + "; val = " + val ) ; } }


Input: wml2 : Collection / wml2 : observationMember / om : OM_Observation / om : phenomenonTime / gml : TimePeriod [CODESPLIT] public static TimePeriodType initTimePeriod ( TimePeriodType timePeriod , StationTimeSeriesFeature stationFeat ) throws IOException { // @gml:id String id = MarshallingUtil . createIdForType ( TimePeriodType . class ) ; timePeriod . setId ( id ) ; CollectionInfo info ; try { info = new DsgCollectionHelper ( stationFeat ) . calcBounds ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } CalendarDateRange cdr = info . getCalendarDateRange ( stationFeat . getTimeUnit ( ) ) ; if ( cdr != null ) { // gml:beginPosition NcTimePositionType . initBeginPosition ( timePeriod . addNewBeginPosition ( ) , cdr . getStart ( ) ) ; // gml:endPosition NcTimePositionType . initEndPosition ( timePeriod . addNewEndPosition ( ) , cdr . getEnd ( ) ) ; } return timePeriod ; }


Input: Constructs a Grib1Gds object from a pds and predefined tables . [CODESPLIT] public static Grib1Gds factory ( int center , int gridNumber ) { if ( center == 7 ) { return factoryNCEP ( gridNumber ) ; } else throw new IllegalArgumentException ( "Dont have predefined GDS " + gridNumber + " from " + center ) ; }


Input: 21 - 26 61 - 64 : International Exchange and Family of Services ( FOS ) grids . So may be more general than NCEP [CODESPLIT] private static Grib1Gds factoryNCEP ( int gridNumber ) { switch ( gridNumber ) { case 21 : return new NcepLatLon ( gridNumber , 37 , 36 , 0.0F , 0.0F , 90.0F , 180.0F , 5.0F , 2.5F , ( byte ) 0x88 , ( byte ) 64 ) ; case 22 : return new NcepLatLon ( gridNumber , 37 , 36 , 0.0F , - 180.0F , 90.0F , 0.0F , 5.0F , 2.5F , ( byte ) 0x88 , ( byte ) 64 ) ; case 23 : return new NcepLatLon ( gridNumber , 37 , 36 , - 90.0F , 0.0F , 180.0F , 0.0F , 5.0F , 2.5F , ( byte ) 0x88 , ( byte ) 64 ) ; case 24 : return new NcepLatLon ( gridNumber , 37 , 36 , - 90.0F , - 180.0F , 0.0F , 0.0F , 5.0F , 2.5F , ( byte ) 0x88 , ( byte ) 64 ) ; case 25 : return new NcepLatLon ( gridNumber , 72 , 18 , 0.0F , 0.0F , 90.0F , 355.0F , 5.0F , 5.0F , ( byte ) 0x88 , ( byte ) 64 ) ; case 26 : return new NcepLatLon ( gridNumber , 72 , 18 , - 90.0F , 0.0F , 0.0F , 355.0F , 5.0F , 5.0F , ( byte ) 0x88 , ( byte ) 64 ) ; case 61 : return new NcepLatLon ( gridNumber , 91 , 45 , 0.0F , 0.0F , 90.0F , 180.0F , 2.0F , 2.0F , ( byte ) 0x88 , ( byte ) 64 ) ; case 62 : return new NcepLatLon ( gridNumber , 91 , 45 , - 90.0F , 0.0F , 0.0F , 180.0F , 2.0F , 2.0F , ( byte ) 0x88 , ( byte ) 64 ) ; case 63 : return new NcepLatLon ( gridNumber , 91 , 45 , - 90.0F , 0.0F , 0.0F , 180.0F , 2.0F , 2.0F , ( byte ) 0x88 , ( byte ) 64 ) ; case 64 : return new NcepLatLon ( gridNumber , 91 , 45 , - 90.0F , - 180.0F , 0.0F , 0.0F , 2.0F , 2.0F , ( byte ) 0x88 , ( byte ) 64 ) ; case 87 : return new NcepPS ( gridNumber , 81 , 62 , 22.8756F , 239.5089F , 255.0F , 68153.0F , 68153.0F , ( byte ) 0x08 , ( byte ) 64 ) ; } throw new IllegalArgumentException ( "Dont have predefined GDS " + gridNumber + " from NCEP (center 7)" ) ; }


Input:
copy all bytes from in and throw them away . [CODESPLIT] static public long copy2null ( InputStream in , int buffersize ) throws IOException { long totalBytesRead = 0 ; if ( buffersize <= 0 ) buffersize = default_file_buffersize ; byte [ ] buffer = new byte [ buffersize ] ; while ( true ) { int n = in . read ( buffer ) ; if ( n == - 1 ) break ; totalBytesRead += n ; } // if (fout != null) fout.format("done=%d %n",totalBytesRead);
 return totalBytesRead ; }


Input: copy all bytes from in and throw them away . [CODESPLIT] static public long copy2null ( FileChannel in , int buffersize ) throws IOException { long totalBytesRead = 0 ; if ( buffersize <= 0 ) buffersize = default_file_buffersize ; ByteBuffer buffer = ByteBuffer . allocate ( buffersize ) ; while ( true ) { int n = in . read ( buffer ) ; if ( n == - 1 ) break ; totalBytesRead += n ; buffer . flip ( ) ; } return totalBytesRead ; }


Input: copy all bytes from in to out specify buffer size [CODESPLIT] static public long copyB ( InputStream in , OutputStream out , int bufferSize ) throws IOException { long totalBytesRead = 0 ; int done = 0 , next = 1 ; byte [ ] buffer = new byte [ bufferSize ] ; while ( true ) { int n = in . read ( buffer ) ; if ( n == - 1 ) break ; out . write ( buffer , 0 , n ) ; totalBytesRead += n ; if ( showCopy ) { done += n ; if ( done > 1000 * 1000 * next ) { System . out . println ( next + " Mb" ) ; next ++ ; } } } out . flush ( ) ; return totalBytesRead ; }


Input: Read the contents from the inputStream and place into a String with any error messages put in the return String . [CODESPLIT] static public String readContents ( InputStream is , String charset ) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream ( 10 * default_file_buffersize ) ; IO . copy ( is , bout ) ; return bout . toString ( charset ) ; }


Input: Read the contents from the inputStream and place into a byte array with any error messages put in the return String . [CODESPLIT] static public byte [ ] readContentsToByteArray ( InputStream is ) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream ( 10 * default_file_buffersize ) ; IO . copy ( is , bout ) ; return bout . toByteArray ( ) ; }


Input: Wite the contents from the String to a Stream [CODESPLIT] static public void writeContents ( String contents , OutputStream os ) throws IOException { ByteArrayInputStream bin = new ByteArrayInputStream ( contents . getBytes ( CDM . utf8Charset ) ) ; IO . copy ( bin , os ) ; }


Input: copy one file to another . [CODESPLIT] static public void copyFile ( String fileInName , String fileOutName ) throws IOException { try ( FileInputStream fin = new FileInputStream ( fileInName ) ; FileOutputStream fout = new FileOutputStream ( fileOutName ) ) { InputStream in = new BufferedInputStream ( fin ) ; OutputStream out = new BufferedOutputStream ( fout ) ; IO . copy ( in , out ) ; } }


Input: copy one file to another . [CODESPLIT] static public void copyFile ( File fileIn , File fileOut ) throws IOException { try ( FileInputStream fin = new FileInputStream ( fileIn ) ; FileOutputStream fout = new FileOutputStream ( fileOut ) ) { InputStream in = new BufferedInputStream ( fin ) ; OutputStream out = new BufferedOutputStream ( fout ) ; IO . copy ( in , out ) ; } }


Input: copy file to output stream [CODESPLIT] static public void copy2File ( byte [ ] src , String fileOut ) throws IOException { try ( FileOutputStream fout = new FileOutputStream ( fileOut ) ) { InputStream in = new BufferedInputStream ( new ByteArrayInputStream ( src ) ) ; OutputStream out = new BufferedOutputStream ( fout ) ; IO . copy ( in , out ) ; } }


Input: copy file to output stream [CODESPLIT] static public void copyFile ( String fileInName , OutputStream out ) throws IOException { copyFileB ( new File ( fileInName ) , out , default_file_buffersize ) ; }


Input: copy file to output stream specify internal buffer size [CODESPLIT] static public void copyFileB ( File fileIn , OutputStream out , int bufferSize ) throws IOException { try ( FileInputStream fin = new FileInputStream ( fileIn ) ) { InputStream in = new BufferedInputStream ( fin ) ; IO . copyB ( in , out , bufferSize ) ; } }


Input: Copy part of a RandomAccessFile to output stream specify internal buffer size [CODESPLIT] static public long copyRafB ( ucar . unidata . io . RandomAccessFile raf , long offset , long length , OutputStream out , byte [ ] buffer ) throws IOException { int bufferSize = buffer . length ; long want = length ; raf . seek ( offset ) ; while ( want > 0 ) { int len = ( int ) Math . min ( want , bufferSize ) ; int bytesRead = raf . read ( buffer , 0 , len ) ; if ( bytesRead <= 0 ) break ; out . write ( buffer , 0 , bytesRead ) ; want -= bytesRead ; } out . flush ( ) ; return length - want ; }


Input: Copy an entire directory tree . [CODESPLIT] static public void copyDirTree ( String fromDirName , String toDirName ) throws IOException { File fromDir = new File ( fromDirName ) ; File toDir = new File ( toDirName ) ; if ( ! fromDir . exists ( ) ) return ; if ( ! toDir . exists ( ) ) { if ( ! toDir . mkdirs ( ) ) { throw new IOException ( "Could not create directory: " + toDir ) ; } } File [ ] files = fromDir . listFiles ( ) ; if ( files != null ) for ( File f : files ) { if ( f . isDirectory ( ) ) copyDirTree ( f . getAbsolutePath ( ) , toDir . getAbsolutePath ( ) + "/" + f . getName ( ) ) ; else copyFile ( f . getAbsolutePath ( ) , toDir . getAbsolutePath ( ) + "/" + f . getName ( ) ) ; } }


Input: Read the file and place contents into a byte array with any error messages put in the return String . [CODESPLIT] static public byte [ ] readFileToByteArray ( String filename ) throws IOException { try ( FileInputStream fin = new FileInputStream ( filename ) ) { InputStream in = new BufferedInputStream ( fin ) ; return readContentsToByteArray ( in ) ; } }


Input: Read the contents from the named file and place into a String assuming UTF - 8 encoding . [CODESPLIT] static public String readFile ( String filename ) throws IOException { try ( FileInputStream fin = new FileInputStream ( filename ) ) { InputStreamReader reader = new InputStreamReader ( fin , CDM . utf8Charset ) ; StringWriter swriter = new StringWriter ( 50000 ) ; UnsynchronizedBufferedWriter writer = new UnsynchronizedBufferedWriter ( swriter ) ; writer . write ( reader ) ; return swriter . toString ( ) ; } }


Input: Write String contents to a file using UTF - 8 encoding . [CODESPLIT] static public void writeToFile ( String contents , File file ) throws IOException { try ( FileOutputStream fout = new FileOutputStream ( file ) ) { OutputStreamWriter fw = new OutputStreamWriter ( fout , CDM . utf8Charset ) ; UnsynchronizedBufferedWriter writer = new UnsynchronizedBufferedWriter ( fw ) ; writer . write ( contents ) ; writer . flush ( ) ; } }


Input: Write byte [] contents to a file . [CODESPLIT] static public void writeToFile ( byte [ ] contents , File file ) throws IOException { try ( FileOutputStream fw = new FileOutputStream ( file ) ) { fw . write ( contents ) ; fw . flush ( ) ; } }


Input: Write contents to a file using UTF - 8 encoding . [CODESPLIT] static public void writeToFile ( String contents , String fileOutName ) throws IOException { writeToFile ( contents , new File ( fileOutName ) ) ; }


Input: copy input stream to file . close input stream when done . [CODESPLIT] static public long writeToFile ( InputStream in , String fileOutName ) throws IOException { try ( FileOutputStream fout = new FileOutputStream ( fileOutName ) ) { OutputStream out = new BufferedOutputStream ( fout ) ; return IO . copy ( in , out ) ; } finally { if ( null != in ) in . close ( ) ; } }


Input:
copy contents of URL to output stream specify internal buffer size . request gzip encoding [CODESPLIT] static public long copyUrlB ( String urlString , OutputStream out , int bufferSize ) throws IOException { long count ; URL url ; try { url = new URL ( urlString ) ; } catch ( MalformedURLException e ) { throw new IOException ( "** MalformedURLException on URL <" + urlString + ">\n" + e . getMessage ( ) + "\n" ) ; } try { java . net . URLConnection connection = url . openConnection ( ) ; java . net . HttpURLConnection httpConnection = null ; if ( connection instanceof java . net . HttpURLConnection ) { httpConnection = ( java . net . HttpURLConnection ) connection ; httpConnection . addRequestProperty ( "Accept-Encoding" , "gzip" ) ; } if ( showHeaders ) { showRequestHeaders ( urlString , connection ) ; } // get response
 if ( httpConnection != null ) { int responseCode = httpConnection . getResponseCode ( ) ; if ( responseCode / 100 != 2 ) throw new IOException ( "** Cant open URL <" + urlString + ">\n Response code = " + responseCode + "\n" + httpConnection . getResponseMessage ( ) + "\n" ) ; } if ( showHeaders && ( httpConnection != null ) ) { int code = httpConnection . getResponseCode ( ) ; String response = httpConnection . getResponseMessage ( ) ; // response headers
 System . out . println ( "\nRESPONSE for " + urlString + ": " ) ; System . out . println ( " HTTP/1.x " + code + " " + response ) ; System . out . println ( "Headers: " ) ; for ( int j = 1 ; ; j ++ ) { String header = connection . getHeaderField ( j ) ; String key = connection . getHeaderFieldKey ( j ) ; if ( header == null || key == null ) break ; System . out . println ( " " + key + ": " + header ) ; } } // read it
 try ( InputStream is = connection . getInputStream ( ) ) { BufferedInputStream bis ; // check if its gzipped
 if ( "gzip" . equalsIgnoreCase ( connection . getContentEncoding ( ) ) ) { bis = new BufferedInputStream ( new GZIPInputStream ( is ) , 8000 ) ; } else { bis = new BufferedInputStream ( is , 8000 ) ; } if ( out == null ) count = IO . copy2null ( bis , bufferSize ) ; else count = IO . copyB ( bis , out , bufferSize ) ; } } catch ( java . net . ConnectException e ) { if ( showStackTrace ) e . printStackTrace ( ) ; throw new IOException ( "** ConnectException on URL: <" + urlString + ">\n" + e . getMessage ( ) + "\nServer probably not running" ) ; } catch ( java . net . UnknownHostException e ) { if ( showStackTrace ) e . printStackTrace ( ) ; throw new IOException ( "** UnknownHostException on URL: <" + urlString + ">\n" ) ; } catch ( Exception e ) { if ( showStackTrace ) e . printStackTrace ( ) ; throw new IOException ( "** Exception on URL: <" + urlString + ">\n" + e ) ; } return count ; }


Input: Turns a ParseException into a OPeNDAP DAP2 error and sends it to the client . [CODESPLIT] public void parseExceptionHandler ( ParseException pe , HttpServletResponse response ) { //log.error("DODSServlet.parseExceptionHandler", pe); if ( Debug . isSet ( "showException" ) ) { log . error ( pe . toString ( ) ) ; printThrowable ( pe ) ; } try { BufferedOutputStream eOut = new BufferedOutputStream ( response . getOutputStream ( ) ) ; response . setHeader ( "Content-Description" , "dods-error" ) ; // This should probably be set to "plain" but this works, the // C++ slients don't barf as they would if I sent "plain" AND // the C++ don't expect compressed data if I do this... response . setHeader ( "Content-Encoding" , "" ) ; // response.setContentType("text/plain"); // Strip any double quotes out of the parser error message. // These get stuck in auto-magically by the javacc generated parser // code and they break our error parser (bummer!) String msg = pe . getMessage ( ) . replace ( ' ' , ' ' ) ; DAP2Exception de2 = new DAP2Exception ( opendap . dap . DAP2Exception . CANNOT_READ_FILE , msg ) ; de2 . print ( eOut ) ; } catch ( IOException ioe ) { log . error ( "Cannot respond to client! IO Error: " + ioe . getMessage ( ) ) ; } }


Input: Sends a OPeNDAP DAP2 error to the client . [CODESPLIT] public void dap2ExceptionHandler ( DAP2Exception de , HttpServletResponse response ) { //log.info("DODSServlet.dodsExceptionHandler (" + de.getErrorCode() + ") " + de.getErrorMessage()); if ( Debug . isSet ( "showException" ) ) { log . error ( de . toString ( ) ) ; de . printStackTrace ( ) ; printDODSException ( de ) ; } // Convert Dap2Excaption code to an HttpCode switch ( de . getErrorCode ( ) ) { case DAP2Exception . NO_SUCH_FILE : case DAP2Exception . CANNOT_READ_FILE : response . setStatus ( HttpStatus . SC_NOT_FOUND ) ; break ; case DAP2Exception . NO_AUTHORIZATION : response . setStatus ( HttpStatus . SC_UNAUTHORIZED ) ; break ; case DAP2Exception . NO_SUCH_VARIABLE : case DAP2Exception . MALFORMED_EXPR : case DAP2Exception . UNKNOWN_ERROR : // fall thru default : response . setStatus ( HttpStatus . SC_BAD_REQUEST ) ; break ; } try { BufferedOutputStream eOut = new BufferedOutputStream ( response . getOutputStream ( ) ) ; response . setHeader ( "Content-Description" , "dods-error" ) ; // This should probably be set to "plain" but this works, the // C++ slients don't barf as they would if I sent "plain" AND // the C++ don't expect compressed data if I do this... response . setHeader ( "Content-Encoding" , "" ) ; de . print ( eOut ) ; } catch ( IOException ioe ) { log . error ( "Cannot respond to client! IO Error: " + ioe . getMessage ( ) ) ; } }


Input: Sends an error to the client . fix : The problem is that if the message is already committed when the IOException occurs the headers dont get set . [CODESPLIT] public void IOExceptionHandler ( IOException e , ReqState rs ) { HttpServletResponse response = rs . getResponse ( ) ; try { BufferedOutputStream eOut = new BufferedOutputStream ( response . getOutputStream ( ) ) ; response . setHeader ( "Content-Description" , "dods-error" ) ; // This should probably be set to "plain" but this works, the // C++ slients don't barf as they would if I sent "plain" AND // the C++ don't expect compressed data if I do this... response . setHeader ( "Content-Encoding" , "" ) ; // Strip any double quotes out of the parser error message. // These get stuck in auto-magically by the javacc generated parser // code and they break our error parser (bummer!) String msg = e . getMessage ( ) ; if ( msg != null ) msg = msg . replace ( ' ' , ' ' ) ; DAP2Exception de2 = new DAP2Exception ( opendap . dap . DAP2Exception . CANNOT_READ_FILE , msg ) ; de2 . print ( eOut ) ; if ( Debug . isSet ( "showException" ) ) { // Error message log . error ( "DODServlet ERROR (IOExceptionHandler): " + e ) ; log . error ( rs . toString ( ) ) ; if ( track ) { RequestDebug reqD = ( RequestDebug ) rs . getUserObject ( ) ; log . error ( "  request number: " + reqD . reqno + " thread: " + reqD . threadDesc ) ; } printThrowable ( e ) ; } } catch ( IOException ioe ) { log . error ( "Cannot respond to client! IO Error: " + ioe . getMessage ( ) ) ; } }


Input: Sends a OPeNDAP DAP2 error ( type UNKNOWN ERROR ) to the client and displays a message on the server console . [CODESPLIT] public void sendDODSError ( ReqState rs , String clientMsg , String serverMsg ) throws Exception { rs . getResponse ( ) . setContentType ( "text/plain" ) ; rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; rs . getResponse ( ) . setHeader ( "Content-Description" , "dods-error" ) ; // Commented because of a bug in the OPeNDAP C++ stuff... //response.setHeader("Content-Encoding", "none"); ServletOutputStream Out = rs . getResponse ( ) . getOutputStream ( ) ; DAP2Exception de = new DAP2Exception ( opendap . dap . DAP2Exception . UNKNOWN_ERROR , clientMsg ) ; de . print ( Out ) ; rs . getResponse ( ) . setStatus ( HttpServletResponse . SC_OK ) ; log . error ( serverMsg ) ; }


Input: Handler for the client s DDX request . Requires the getDDX () method implemented by each server localization effort . <p > <p > Once the DDX has been parsed and constrained it is sent to the requesting client . [CODESPLIT] public void doGetDDX ( ReqState rs ) throws Exception { if ( Debug . isSet ( "showResponse" ) ) { log . debug ( "doGetDDX for dataset: " + rs . getDataSet ( ) ) ; } GuardedDataset ds = null ; try { ds = getDataset ( rs ) ; if ( null == ds ) return ; rs . getResponse ( ) . setContentType ( "text/plain" ) ; rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; rs . getResponse ( ) . setHeader ( "Content-Description" , "dods-ddx" ) ; // Commented because of a bug in the OPeNDAP C++ stuff... // rs.getResponse().setHeader("Content-Encoding", "plain"); OutputStream Out = new BufferedOutputStream ( rs . getResponse ( ) . getOutputStream ( ) ) ; // Utilize the getDDS() method to get a parsed and populated DDS // for this server. ServerDDS myDDS = ds . getDDS ( ) ; if ( rs . getConstraintExpression ( ) . equals ( "" ) ) { // No Constraint Expression? // Send the whole DDS myDDS . printXML ( Out ) ; Out . flush ( ) ; } else { // Otherwise, send the constrained DDS // Instantiate the CEEvaluator and parse the constraint expression CEEvaluator ce = new CEEvaluator ( myDDS ) ; ce . parseConstraint ( rs ) ; // Send the constrained DDS back to the client PrintWriter pw = new PrintWriter ( new OutputStreamWriter ( Out , Util . UTF8 ) ) ; myDDS . printConstrainedXML ( pw ) ; pw . flush ( ) ; } rs . getResponse ( ) . setStatus ( HttpServletResponse . SC_OK ) ; if ( Debug . isSet ( "showResponse" ) ) { if ( rs . getConstraintExpression ( ) . equals ( "" ) ) { // No Constraint Expression? //          log.debug("Unconstrained DDX=\n"); //          myDDS.printXML(System.out); } else { //          log.debug("Constrained DDX=\n"); //          myDDS.printConstrainedXML(System.out); } } } catch ( ParseException pe ) { parseExceptionHandler ( pe , rs . getResponse ( ) ) ; } catch ( DAP2Exception de ) { dap2ExceptionHandler ( de , rs . getResponse ( ) ) ; } catch ( IOException pe ) { IOExceptionHandler ( pe , rs ) ; } catch ( Throwable t ) { anyExceptionHandler ( t , rs ) ; } finally { // release lock if needed if ( ds != null ) ds . release ( ) ; } }


Input: Handler for the client s data request . Requires the getDDS () method implemented by each server localization effort . <p > <p > Once the DDS has been parsed the data is read ( using the class in the localized server factory etc . ) compared to the constraint expression and then sent to the client . [CODESPLIT] public void doGetBLOB ( ReqState rs ) throws Exception { if ( Debug . isSet ( "showResponse" ) ) { log . debug ( "doGetBLOB For: " + rs . getDataSet ( ) ) ; } GuardedDataset ds = null ; try { ds = getDataset ( rs ) ; if ( ds == null ) return ; rs . getResponse ( ) . setContentType ( "application/octet-stream" ) ; rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; rs . getResponse ( ) . setHeader ( "Content-Description" , "dods-blob" ) ; ServletOutputStream sOut = rs . getResponse ( ) . getOutputStream ( ) ; OutputStream bOut ; DeflaterOutputStream dOut = null ; if ( rs . getAcceptsCompressed ( ) && allowDeflate ) { rs . getResponse ( ) . setHeader ( "Content-Encoding" , "deflate" ) ; dOut = new DeflaterOutputStream ( sOut ) ; bOut = new BufferedOutputStream ( dOut ) ; } else { // Commented out because of a bug in the OPeNDAP C++ stuff... //rs.getResponse().setHeader("Content-Encoding", "plain"); bOut = new BufferedOutputStream ( sOut ) ; } // Utilize the getDDS() method to get // a parsed and populated DDS // for this server. ServerDDS myDDS = ds . getDDS ( ) ; cacheArrayShapes ( myDDS ) ; // Instantiate the CEEvaluator and parse the constraint expression CEEvaluator ce = new CEEvaluator ( myDDS , new ClauseFactory ( functionLibrary ) ) ; ce . parseConstraint ( rs . getConstraintExpression ( ) , rs . getRequestURL ( ) . toString ( ) ) ; // Send the binary data back to the client DataOutputStream sink = new DataOutputStream ( bOut ) ; int seqLength = 5 ; String sls = rs . getInitParameter ( "SequenceLength" ) ; if ( sls != null ) { seqLength = ( Integer . valueOf ( sls ) ) . intValue ( ) ; } testEngine te = new testEngine ( seqLength ) ; ce . send ( myDDS . getEncodedName ( ) , sink , te ) ; sink . flush ( ) ; // Finish up sending the compressed stuff, but don't // close the stream (who knows what the Servlet may expect!) if ( rs . getAcceptsCompressed ( ) ) { if ( bOut != null ) bOut . flush ( ) ; if ( dOut != null ) ( ( DeflaterOutputStream ) dOut ) . finish ( ) ; } //? if(null != dOut) dOut.finish(); //? bOut.flush(); rs . getResponse ( ) . setStatus ( HttpServletResponse . SC_OK ) ; } catch ( ParseException pe ) { parseExceptionHandler ( pe , rs . getResponse ( ) ) ; } catch ( DAP2Exception de ) { dap2ExceptionHandler ( de , rs . getResponse ( ) ) ; } catch ( IOException ioe ) { IOExceptionHandler ( ioe , rs ) ; } finally { // release lock if needed if ( ds != null ) ds . release ( ) ; } }


Input: Handler for the client s directory request . <p > Returns an html document to the client showing ( a possibly pseudo ) listing of the datasets available on the server in a directory listing format . <p > The bulk of this code resides in the class opendap . servlet . GetDirHandler and documentation may be found there . [CODESPLIT] public void doGetDIR ( ReqState rs ) throws Exception { rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; rs . getResponse ( ) . setContentType ( "text/html" ) ; rs . getResponse ( ) . setHeader ( "Content-Description" , "dods-directory" ) ; try { GetDirHandler di = new GetDirHandler ( ) ; di . sendDIR ( rs ) ; rs . getResponse ( ) . setStatus ( HttpServletResponse . SC_OK ) ; } catch ( ParseException pe ) { parseExceptionHandler ( pe , rs . getResponse ( ) ) ; } catch ( DAP2Exception de ) { dap2ExceptionHandler ( de , rs . getResponse ( ) ) ; } catch ( Throwable t ) { anyExceptionHandler ( t , rs ) ; } }


Input: Sends an html document to the client explaining that they have used a poorly formed URL and then the help page ... [CODESPLIT] public void badURL ( HttpServletRequest request , HttpServletResponse response ) throws Exception { if ( Debug . isSet ( "showResponse" ) ) { log . debug ( "Sending Bad URL Page." ) ; } //log.info("DODSServlet.badURL " + rs.getRequest().getRequestURI()); response . setContentType ( "text/html" ) ; response . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; response . setHeader ( "Content-Description" , "dods-error" ) ; // Commented because of a bug in the OPeNDAP C++ stuff... //rs.getResponse().setHeader("Content-Encoding", "plain"); PrintWriter pw = new PrintWriter ( new OutputStreamWriter ( response . getOutputStream ( ) , Util . UTF8 ) ) ; printBadURLPage ( pw ) ; printHelpPage ( pw ) ; pw . flush ( ) ; response . setStatus ( HttpServletResponse . SC_OK ) ; }


Input: Handler for OPeNDAP info requests . Returns an HTML document describing the contents of the servers datasets . <p > The bulk of this code resides in the class opendap . servlet . GetInfoHandler and documentation may be found there . [CODESPLIT] public void doGetINFO ( ReqState rs ) throws Exception { if ( Debug . isSet ( "showResponse" ) ) { log . debug ( "doGetINFO For: " + rs . getDataSet ( ) ) ; } GuardedDataset ds = null ; try { ds = getDataset ( rs ) ; if ( ds == null ) return ; PrintWriter pw = new PrintWriter ( new OutputStreamWriter ( rs . getResponse ( ) . getOutputStream ( ) , Util . UTF8 ) ) ; rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; rs . getResponse ( ) . setContentType ( "text/html" ) ; rs . getResponse ( ) . setHeader ( "Content-Description" , "dods-description" ) ; GetInfoHandler di = new GetInfoHandler ( ) ; di . sendINFO ( pw , ds , rs ) ; rs . getResponse ( ) . setStatus ( HttpServletResponse . SC_OK ) ; } catch ( ParseException pe ) { parseExceptionHandler ( pe , rs . getResponse ( ) ) ; } catch ( DAP2Exception de ) { dap2ExceptionHandler ( de , rs . getResponse ( ) ) ; } catch ( IOException pe ) { IOExceptionHandler ( pe , rs ) ; } catch ( Throwable t ) { anyExceptionHandler ( t , rs ) ; } finally { // release lock if needed if ( ds != null ) ds . release ( ) ; } }


Input: Handler for OPeNDAP . html requests . Returns the OPeNDAP Web Interface ( aka The Interface From Hell ) to the client . <p > The bulk of this code resides in the class opendap . servlet . GetHTMLInterfaceHandler and documentation may be found there . [CODESPLIT] public void doGetHTML ( ReqState rs ) throws Exception { GuardedDataset ds = null ; try { ds = getDataset ( rs ) ; if ( ds == null ) return ; rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; rs . getResponse ( ) . setContentType ( "text/html" ) ; rs . getResponse ( ) . setHeader ( "Content-Description" , "dods-form" ) ; // Utilize the getDDS() method to get	a parsed and populated DDS // for this server. ServerDDS myDDS = ds . getDDS ( ) ; DAS das = ds . getDAS ( ) ; GetHTMLInterfaceHandler di = new GetHTMLInterfaceHandler ( ) ; di . sendDataRequestForm ( rs , rs . getDataSet ( ) , myDDS , das ) ; rs . getResponse ( ) . setStatus ( HttpServletResponse . SC_OK ) ; } catch ( ParseException pe ) { parseExceptionHandler ( pe , rs . getResponse ( ) ) ; } catch ( DAP2Exception de ) { dap2ExceptionHandler ( de , rs . getResponse ( ) ) ; } catch ( IOException pe ) { IOExceptionHandler ( pe , rs ) ; } catch ( Throwable t ) { anyExceptionHandler ( t , rs ) ; } finally { // release lock if needed if ( ds != null ) ds . release ( ) ; } }


Input: Handler for OPeNDAP catalog . xml requests . [CODESPLIT] public void doGetCatalog ( ReqState rs ) throws Exception { rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; rs . getResponse ( ) . setContentType ( "text/xml" ) ; rs . getResponse ( ) . setHeader ( "Content-Description" , "dods-catalog" ) ; PrintWriter pw = new PrintWriter ( new OutputStreamWriter ( rs . getResponse ( ) . getOutputStream ( ) , Util . UTF8 ) ) ; printCatalog ( rs , pw ) ; pw . flush ( ) ; rs . getResponse ( ) . setStatus ( HttpServletResponse . SC_OK ) ; }


Input: to be overridden by servers that implement catalogs [CODESPLIT] protected void printCatalog ( ReqState rs , PrintWriter os ) throws IOException { os . println ( "Catalog not available for this server" ) ; os . println ( "Server version = " + getServerVersion ( ) ) ; }


Input:
Handler for OPeNDAP status requests ; not publically available used only for debugging [CODESPLIT] public void doGetSystemProps ( ReqState rs ) throws Exception { rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; rs . getResponse ( ) . setContentType ( "text/html" ) ; rs . getResponse ( ) . setHeader ( "Content-Description" , "dods-status" ) ; PrintWriter pw = new PrintWriter ( new OutputStreamWriter ( rs . getResponse ( ) . getOutputStream ( ) , Util . UTF8 ) ) ; pw . println ( "" ) ; pw . println ( "<title>System Properties</title>" ) ; pw . println ( "
" ) ; pw . println ( "
System Properties
" ) ; pw . println ( "
Date: " + new Date ( ) + "
" ) ; Properties sysp = System . getProperties ( ) ; Enumeration e = sysp . propertyNames ( ) ; pw . println ( "
" ) ; while ( e . hasMoreElements ( ) ) { String name = ( String ) e . nextElement ( ) ; String value = System . getProperty ( name ) ; pw . println ( "
" + name + ": " + value + "
" ) ; } pw . println ( "
" ) ; pw . println ( "
Runtime Info:
" ) ; Runtime rt = Runtime . getRuntime ( ) ; pw . println ( "JVM Max Memory:   " + ( rt . maxMemory ( ) / 1024 ) / 1000. + " MB (JVM Maximum Allowable Heap)
" ) ; pw . println ( "JVM Total Memory: " + ( rt . totalMemory ( ) / 1024 ) / 1000. + " MB (JVM Heap size)
" ) ; pw . println ( "JVM Free Memory:  " + ( rt . freeMemory ( ) / 1024 ) / 1000. + " MB (Unused part of heap)
" ) ; pw . println ( "JVM Used Memory:  " + ( ( rt . totalMemory ( ) - rt . freeMemory ( ) ) / 1024 ) / 1000. + " MB (Currently active memory)
" ) ; pw . println ( "
" ) ; pw . println ( "" ) ; pw . println ( "" ) ; pw . flush ( ) ; rs . getResponse ( ) . setStatus ( HttpServletResponse . SC_OK ) ; }


Input:
Handler for OPeNDAP status requests ; not publically available used only for debugging [CODESPLIT] public void doGetStatus ( ReqState rs ) throws Exception { rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; rs . getResponse ( ) . setContentType ( "text/html" ) ; rs . getResponse ( ) . setHeader ( "Content-Description" , "dods-status" ) ; PrintWriter pw = new PrintWriter ( new OutputStreamWriter ( rs . getResponse ( ) . getOutputStream ( ) , Util . UTF8 ) ) ; pw . println ( "<title>Server Status</title>" ) ; pw . println ( "
" ) ; printStatus ( pw ) ; pw . println ( "
" ) ; pw . flush ( ) ; rs . getResponse ( ) . setStatus ( HttpServletResponse . SC_OK ) ; }


Input:
to be overridden by servers that implement status report [CODESPLIT] protected void printStatus ( PrintWriter os ) { os . println ( "
Server version = " + getServerVersion ( ) + "
" ) ; os . println ( "
Number of Requests Received = " + HitCounter + "
" ) ; if ( track ) { int n = prArr . size ( ) ; int pending = 0 ; StringBuilder preqs = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { ReqState rs = ( ReqState ) prArr . get ( i ) ; RequestDebug reqD = ( RequestDebug ) rs . getUserObject ( ) ; if ( ! reqD . done ) { preqs . append ( "
-----------------------\n" ) ; preqs . append ( "Request[" ) ; preqs . append ( reqD . reqno ) ; preqs . append ( "](" ) ; preqs . append ( reqD . threadDesc ) ; preqs . append ( ") is pending.\n" ) ; preqs . append ( rs . toString ( ) ) ; preqs . append ( "
" ) ; pending ++ ; } } os . println ( "
" + pending + " Pending Request(s)
" ) ; os . println ( preqs . toString ( ) ) ; } }


Input: This is a bit of instrumentation that I kept around to let me look at the state of the incoming <code > HttpServletRequest< / code > from the client . This method calls the <code > get * < / code > methods of the request and prints the results to standard out . [CODESPLIT] public void probeRequest ( PrintStream ps , ReqState rs ) { Enumeration e ; int i ; HttpServletRequest request = rs . getRequest ( ) ; ps . println ( "####################### PROBE ##################################" ) ; ps . println ( "The HttpServletRequest object is actually a: " + request . getClass ( ) . getName ( ) ) ; ps . println ( "" ) ; ps . println ( "HttpServletRequest Interface:" ) ; ps . println ( "    getAuthType:           " + request . getAuthType ( ) ) ; ps . println ( "    getMethod:             " + request . getMethod ( ) ) ; ps . println ( "    getPathInfo:           " + request . getPathInfo ( ) ) ; ps . println ( "    getPathTranslated:     " + request . getPathTranslated ( ) ) ; ps . println ( "    getRequestURL:         " + request . getRequestURL ( ) ) ; ps . println ( "    getQueryString:        " + request . getQueryString ( ) ) ; ps . println ( "    getRemoteUser:         " + request . getRemoteUser ( ) ) ; ps . println ( "    getRequestedSessionId: " + request . getRequestedSessionId ( ) ) ; ps . println ( "    getRequestURI:         " + request . getRequestURI ( ) ) ; ps . println ( "    getServletPath:        " + request . getServletPath ( ) ) ; ps . println ( "    isRequestedSessionIdFromCookie: " + request . isRequestedSessionIdFromCookie ( ) ) ; ps . println ( "    isRequestedSessionIdValid:      " + request . isRequestedSessionIdValid ( ) ) ; ps . println ( "    isRequestedSessionIdFromURL:    " + request . isRequestedSessionIdFromURL ( ) ) ; ps . println ( "" ) ; i = 0 ; e = request . getHeaderNames ( ) ; ps . println ( "    Header Names:" ) ; while ( e . hasMoreElements ( ) ) { i ++ ; String s = ( String ) e . nextElement ( ) ; ps . print ( "        Header[" + i + "]: " + s ) ; ps . println ( ": " + request . getHeader ( s ) ) ; } ps . println ( "" ) ; ps . println ( "ServletRequest Interface:" ) ; ps . println ( "    getCharacterEncoding:  " + request . getCharacterEncoding ( ) ) ; ps . println ( "    getContentType:        " + request . getContentType ( ) ) ; ps . println ( "    getContentLength:      " + request . getContentLength ( ) ) ; ps . println ( "    getProtocol:           " + request . getProtocol ( ) ) ; ps . println ( "    getScheme:             " + request . getScheme ( ) ) ; ps . println ( "    getServerName:         " + request . getServerName ( ) ) ; ps . println ( "    getServerPort:         " + request . getServerPort ( ) ) ; ps . println ( "    getRemoteAddr:         " + request . getRemoteAddr ( ) ) ; ps . println ( "    getRemoteHost:         " + request . getRemoteHost ( ) ) ; //ps.println("    getRealPath:           "+request.getRealPath()); ps . println ( "............................." ) ; ps . println ( "" ) ; i = 0 ; e = request . getAttributeNames ( ) ; ps . println ( "    Attribute Names:" ) ; while ( e . hasMoreElements ( ) ) { i ++ ; String s = ( String ) e . nextElement ( ) ; ps . print ( "        Attribute[" + i + "]: " + s ) ; ps . println ( " Type: " + request . getAttribute ( s ) ) ; } ps . println ( "............................." ) ; ps . println ( "" ) ; i = 0 ; e = request . getParameterNames ( ) ; ps . println ( "    Parameter Names:" ) ; while ( e . hasMoreElements ( ) ) { i ++ ; String s = ( String ) e . nextElement ( ) ; ps . print ( "        Parameter[" + i + "]: " + s ) ; ps . println ( " Value: " + request . getParameter ( s ) ) ; } ps . println ( "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" ) ; ps . println ( " . . . . . . . . . Servlet Infomation API  . . . . . . . . . . . . . ." ) ; ps . println ( "" ) ; ps . println ( "Servlet Context:" ) ; ps . println ( "" ) ; i = 0 ; e = servletContext . getAttributeNames ( ) ; ps . println ( "    Attribute Names:" ) ; while ( e . hasMoreElements ( ) ) { i ++ ; String s = ( String ) e . nextElement ( ) ; ps . print ( "        Attribute[" + i + "]: " + s ) ; ps . println ( " Type: " + servletContext . getAttribute ( s ) ) ; } ps . println ( "    ServletContext.getRealPath(\".\"): " + servletContext . getRealPath ( "." ) ) ; ps . println ( "    ServletContext.getMajorVersion(): " + servletContext . getMajorVersion ( ) ) ; //        ps.println("ServletContext.getMimeType():     " + sc.getMimeType()); ps . println ( "    ServletContext.getMinorVersion(): " + servletContext . getMinorVersion ( ) ) ; //        ps.println("ServletContext.getRealPath(): " + sc.getRealPath()); ps . println ( "............................." ) ; ps . println ( "Servlet Config:" ) ; ps . println ( "" ) ; ServletConfig scnfg = getServletConfig ( ) ; i = 0 ; e = scnfg . getInitParameterNames ( ) ; ps . println ( "    InitParameters:" ) ; while ( e . hasMoreElements ( ) ) { String p = ( String ) e . nextElement ( ) ; ps . print ( "        InitParameter[" + i + "]: " + p ) ; ps . println ( " Value: " + scnfg . getInitParameter ( p ) ) ; i ++ ; } ps . println ( "" ) ; ps . println ( "######################## END PROBE ###############################" ) ; ps . println ( "" ) ; }


Input:
Handles incoming requests from clients . Parses the request and determines what kind of OPeNDAP response the client is requesting . If the request is understood then the appropriate handler method is called otherwise an error is returned to the client . <p > This method is the entry point for <code > DTSServlet< / code > . [CODESPLIT] public void doGet ( HttpServletRequest request , HttpServletResponse response ) { log . debug ( "DTS doGet()" ) ; long tid = Thread . currentThread ( ) . getId ( ) ; log . debug ( "thread=" + tid ) ; // setHeader("Last-Modified", (new Date()).toString() ); boolean isDebug = false ; ReqState rs = null ; RequestDebug reqD = null ; try { //      if(Debug.isSet("probeRequest")) //        probeRequest(System.out, rs); rs = getRequestState ( request , response ) ; assert ( rs != null ) ; if ( rs != null ) { String ds = rs . getDataSet ( ) ; String suff = rs . getRequestSuffix ( ) ; isDebug = ( ( ds != null ) && ds . equals ( "debug" ) && ( suff != null ) && suff . equals ( "" ) ) ; } synchronized ( syncLock ) { if ( ! isDebug ) { long reqno = HitCounter ++ ; if ( track ) { reqD = new RequestDebug ( reqno , Thread . currentThread ( ) . toString ( ) ) ; rs . setUserObject ( reqD ) ; if ( prArr == null ) prArr = new ArrayList ( 10000 ) ; prArr . add ( ( int ) reqno , rs ) ; } if ( Debug . isSet ( "showRequest" ) ) { log . debug ( "-------------------------------------------" ) ; log . debug ( "Server: " + getServerName ( ) + "   Request #" + reqno ) ; log . debug ( "Client: " + request . getRemoteHost ( ) ) ; log . debug ( rs . toString ( ) ) ; log . debug ( "Request dataset: '" + rs . getDataSet ( ) + "' suffix: '" + rs . getRequestSuffix ( ) + "' CE: '" + rs . getConstraintExpression ( ) + "'" ) ; } } } // synch if ( rs != null ) { String dataSet = rs . getDataSet ( ) ; String requestSuffix = rs . getRequestSuffix ( ) ; rs . getResponse ( ) . setHeader ( "XDODS-Server" , getServerVersion ( ) ) ; // Make sure always set if ( dataSet == null || dataSet . equals ( "/" ) || dataSet . equals ( "" ) ) { doGetDIR ( rs ) ; } else if ( dataSet . equalsIgnoreCase ( "/version" ) || dataSet . equalsIgnoreCase ( "/version/" ) ) { doGetVER ( rs ) ; } else if ( dataSet . equalsIgnoreCase ( "/help" ) || dataSet . equalsIgnoreCase ( "/help/" ) ) { doGetHELP ( rs ) ; } else if ( dataSet . equalsIgnoreCase ( "/" + requestSuffix ) ) { doGetHELP ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "dds" ) ) { doGetDDS ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "das" ) ) { doGetDAS ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "ddx" ) ) { doGetDDX ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "blob" ) ) { doGetBLOB ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "dods" ) ) { doGetDAP2Data ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "asc" ) || requestSuffix . equalsIgnoreCase ( "ascii" ) ) { doGetASC ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "info" ) ) { doGetINFO ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "html" ) || requestSuffix . equalsIgnoreCase ( "htm" ) ) { doGetHTML ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "ver" ) || requestSuffix . equalsIgnoreCase ( "version" ) ) { doGetVER ( rs ) ; } else if ( requestSuffix . equalsIgnoreCase ( "help" ) ) { doGetHELP ( rs ) ; /* JC added
        } else if(dataSet.equalsIgnoreCase("catalog") && requestSuffix.equalsIgnoreCase("xml")) {
          doGetCatalog(rs);
        } else if(dataSet.equalsIgnoreCase("status")) {
          doGetStatus(rs);
        } else if(dataSet.equalsIgnoreCase("systemproperties")) {
          doGetSystemProps(rs);
        } else if(isDebug) {
          doDebug(rs);  */ } else if ( requestSuffix . equals ( "" ) ) { badURL ( request , response ) ; } else { badURL ( request , response ) ; } } else { // rs == null badURL ( request , response ) ; } if ( reqD != null ) reqD . done = true ; } catch ( Throwable e ) { anyExceptionHandler ( e , rs ) ; } }


Input: ************************************************************************** [CODESPLIT] void showMemUsed ( String from ) { long totalMemory = Runtime . getRuntime ( ) . totalMemory ( ) ; long freeMemory = Runtime . getRuntime ( ) . freeMemory ( ) ; //long maxMemory = Runtime.getRuntime ().maxMemory (); long usedMemory = ( totalMemory - freeMemory ) ; log . debug ( "****showMemUsed " + from ) ; log . debug ( " totalMemory " + totalMemory ) ; log . debug ( " freeMemory " + freeMemory ) ; //log.debug(" maxMemory "+maxMemory); log . debug ( " usedMemory " + usedMemory ) ; }


Input:
Prints the Bad URL Page page to the passed PrintWriter [CODESPLIT] private void printBadURLPage ( PrintWriter pw ) { pw . println ( "
Error in URL
" ) ; pw . println ( "The URL extension did not match any that are known by this" ) ; pw . println ( "server. Below is a list of the five extensions that are be recognized by" ) ; pw . println ( "all OPeNDAP servers. If you think that the server is broken (that the URL you" ) ; pw . println ( "submitted should have worked), then please contact the" ) ; pw . println ( "OPeNDAP user support coordinator at: " ) ; pw . println ( "support@unidata.ucar.edu
" ) ; }


Input: reference reference or base time as Dare . [CODESPLIT] public CalendarDate getReferenceDate ( ) { return CalendarDate . of ( null , year , month , day , hour , minute , second ) ; }


Input:
Add an entity for resolution . Specify a local resource and / or a URL . Look for the local Resource first . [CODESPLIT] static public void initEntity ( String entityName , String resourceName , String urlName ) { String entity = null ; try ( InputStream is = ucar . nc2 . util . IO . getFileResource ( resourceName ) ) { // try to read from local file resource, eg from catalog.jar
 ByteArrayOutputStream sbuff = new ByteArrayOutputStream ( 3000 ) ; if ( is != null ) { IO . copy ( is , sbuff ) ; entity = new String ( sbuff . toByteArray ( ) , CDM . utf8Charset ) ; logger . debug ( " *** entity " + entityName + " mapped to local resource at " + resourceName ) ; } else if ( urlName != null ) { // otherwise, get from network
 entity = IO . readURLcontentsWithException ( urlName ) ; logger . debug ( " *** entity " + entityName + " mapped to remote URL at " + urlName ) ; } } catch ( IOException e ) { System . out . println ( " *** FAILED to map entity " + entityName + " locally at " + resourceName + " or remotely at " + urlName ) ; // e.printStackTrace();
 } entityHash . put ( entityName , entity ) ; entityHash . put ( urlName , entity ) ; // also map it to the remote URL
 }


Input: we read the DTD / schema locally if we can . [CODESPLIT] public org . xml . sax . InputSource resolveEntity ( String publicId , String systemId ) throws SAXException , IOException { logger . debug ( "  publicId=" + publicId + " systemId=" + systemId ) ; String entity = entityHash . get ( systemId ) ; if ( entity != null ) { logger . debug ( " *** resolved  with local copy" ) ; return new MyInputSource ( entity ) ; } if ( systemId . contains ( "InvCatalog.0.6.dtd" ) ) { entity = entityHash . get ( "http://www.unidata.ucar.edu/schemas/thredds/InvCatalog.0.6.dtd" ) ; if ( entity != null ) { logger . debug ( " *** resolved2 with local copy" ) ; return new MyInputSource ( entity ) ; } } logger . debug ( " *** not resolved" ) ; return null ; }


Input:
lOOK probably desnt work [CODESPLIT] private Array readVlenData ( Variable v , Section section , DataStorage dataStorage ) throws IOException , InvalidRangeException { raf . seek ( dataStorage . filePos ) ; int nelems = readVInt ( raf ) ; Array [ ] result = new Array [ nelems ] ; for ( int elem = 0 ; elem < nelems ; elem ++ ) { int dsize = readVInt ( raf ) ; byte [ ] data = new byte [ dsize ] ; raf . readFully ( data ) ; Array dataArray = Array . factory ( v . getDataType ( ) , ( int [ ] ) null , ByteBuffer . wrap ( data ) ) ; result [ elem ] = dataArray ; } // return Array.makeObjectArray(v.getDataType(), result[0].getClass(), new int[]{nelems}, result);
 return Array . makeVlenArray ( new int [ ] { nelems } , result ) ; //return dataArray.section(section.getRanges());
 }


Input:
optionally read in all messages return as List<NcMess > [CODESPLIT] public void openDebug ( RandomAccessFile raf , NetcdfFile ncfile , List < NcsMess > ncm ) throws IOException { raf . seek ( 0 ) ; long pos = raf . getFilePointer ( ) ; if ( ! readAndTest ( raf , NcStream . MAGIC_START ) ) { if ( ncm != null ) { ncm . add ( new NcsMess ( pos , 0 , "MAGIC_START missing - abort" ) ) ; return ; } throw new IOException ( "Data corrupted on " + raf . getLocation ( ) ) ; } if ( ncm != null ) ncm . add ( new NcsMess ( pos , 4 , "MAGIC_START" ) ) ; pos = raf . getFilePointer ( ) ; if ( ! readAndTest ( raf , NcStream . MAGIC_HEADER ) ) { if ( ncm != null ) { ncm . add ( new NcsMess ( pos , 0 , "MAGIC_HEADER missing - abort" ) ) ; return ; } throw new IOException ( "Data corrupted on " + ncfile . getLocation ( ) ) ; } if ( ncm != null ) ncm . add ( new NcsMess ( pos , 4 , "MAGIC_HEADER" ) ) ; // assume for the moment it always starts with one header message
 pos = raf . getFilePointer ( ) ; int msize = readVInt ( raf ) ; byte [ ] m = new byte [ msize ] ; raf . readFully ( m ) ; NcStreamProto . Header proto = NcStreamProto . Header . parseFrom ( m ) ; if ( ncm != null ) ncm . add ( new NcsMess ( pos , msize , proto ) ) ; version = proto . getVersion ( ) ; NcStreamProto . Group root = proto . getRoot ( ) ; NcStream . readGroup ( root , ncfile , ncfile . getRootGroup ( ) ) ; ncfile . finish ( ) ; // then we have a stream of data messages with a final END or ERR
 while ( ! raf . isAtEndOfFile ( ) ) { pos = raf . getFilePointer ( ) ; byte [ ] b = new byte [ 4 ] ; raf . readFully ( b ) ; if ( test ( b , NcStream . MAGIC_END ) ) { if ( ncm != null ) ncm . add ( new NcsMess ( pos , 4 , "MAGIC_END" ) ) ; break ; } if ( test ( b , NcStream . MAGIC_ERR ) ) { int esize = readVInt ( raf ) ; byte [ ] dp = new byte [ esize ] ; raf . readFully ( dp ) ; NcStreamProto . Error error = NcStreamProto . Error . parseFrom ( dp ) ; if ( ncm != null ) ncm . add ( new NcsMess ( pos , esize , error . getMessage ( ) ) ) ; break ; // assume broken now ?
 } if ( ! test ( b , NcStream . MAGIC_DATA ) ) { if ( ncm != null ) ncm . add ( new NcsMess ( pos , 4 , "MAGIC_DATA missing - abort" ) ) ; break ; } if ( ncm != null ) ncm . add ( new NcsMess ( pos , 4 , "MAGIC_DATA" ) ) ; // data messages
 pos = raf . getFilePointer ( ) ; int psize = readVInt ( raf ) ; byte [ ] dp = new byte [ psize ] ; raf . readFully ( dp ) ; NcStreamProto . Data dproto = NcStreamProto . Data . parseFrom ( dp ) ; ByteOrder bo = NcStream . decodeDataByteOrder ( dproto ) ; // LOOK not using bo !!
 Variable v = ncfile . findVariable ( dproto . getVarName ( ) ) ; if ( v == null ) { System . out . printf ( " ERR cant find var %s%n%s%n" , dproto . getVarName ( ) , dproto ) ; } if ( debug ) System . out . printf ( " dproto = %s for %s%n" , dproto , v . getShortName ( ) ) ; if ( ncm != null ) ncm . add ( new NcsMess ( pos , psize , dproto ) ) ; List < DataStorage > storage ; if ( v != null ) { storage = ( List < DataStorage > ) v . getSPobject ( ) ; // LOOK could be an in memory Rtree using section
 if ( storage == null ) { storage = new ArrayList <> ( ) ; v . setSPobject ( storage ) ; } } else storage = new ArrayList <> ( ) ; // barf
 // version < 3
 if ( dproto . getDataType ( ) == NcStreamProto . DataType . STRUCTURE ) { pos = raf . getFilePointer ( ) ; msize = readVInt ( raf ) ; m = new byte [ msize ] ; raf . readFully ( m ) ; NcStreamProto . StructureData sdata = NcStreamProto . StructureData . parseFrom ( m ) ; DataStorage dataStorage = new DataStorage ( msize , pos , dproto ) ; dataStorage . sdata = sdata ; if ( ncm != null ) ncm . add ( new NcsMess ( dataStorage . filePos , msize , sdata ) ) ; storage . add ( dataStorage ) ; } else if ( dproto . getVdata ( ) ) { DataStorage dataStorage = new DataStorage ( 0 , raf . getFilePointer ( ) , dproto ) ; int nelems = readVInt ( raf ) ; int totalSize = 0 ; for ( int i = 0 ; i < nelems ; i ++ ) { int dsize = readVInt ( raf ) ; totalSize += dsize ; raf . skipBytes ( dsize ) ; } dataStorage . nelems = nelems ; dataStorage . size = totalSize ; if ( ncm != null ) ncm . add ( new NcsMess ( dataStorage . filePos , totalSize , dataStorage ) ) ; storage . add ( dataStorage ) ; } else { // regular data
 int dsize = readVInt ( raf ) ; DataStorage dataStorage = new DataStorage ( dsize , raf . getFilePointer ( ) , dproto ) ; if ( ncm != null ) ncm . add ( new NcsMess ( dataStorage . filePos , dsize , dataStorage ) ) ; storage . add ( dataStorage ) ; raf . skipBytes ( dsize ) ; } } }


Input: Read an NcML file from a String and construct a NcmlCollectionReader from its scan or scanFmrc element . [CODESPLIT] static public NcmlCollectionReader readNcML ( String ncmlString , Formatter errlog ) throws IOException { StringReader reader = new StringReader ( ncmlString ) ; org . jdom2 . Document doc ; try { SAXBuilder builder = new SAXBuilder ( ) ; if ( debugURL ) System . out . println ( " NetcdfDataset NcML String = <" + ncmlString + ">" ) ; doc = builder . build ( new StringReader ( ncmlString ) ) ; } catch ( JDOMException e ) { throw new IOException ( e . getMessage ( ) ) ; } if ( debugXML ) System . out . println ( " SAXBuilder done" ) ; return readXML ( doc , errlog , null ) ; }


Input: Read an NcML file from a URL location and construct a NcmlCollectionReader from its scan or scanFmrc element . [CODESPLIT] static public NcmlCollectionReader open ( String ncmlLocation , Formatter errlog ) throws IOException { if ( ! ncmlLocation . startsWith ( "http:" ) && ! ncmlLocation . startsWith ( "file:" ) ) ncmlLocation = "file:" + ncmlLocation ; URL url = new URL ( ncmlLocation ) ; org . jdom2 . Document doc ; try { SAXBuilder builder = new SAXBuilder ( ) ; if ( debugURL ) System . out . println ( " NetcdfDataset URL = <" + url + ">" ) ; doc = builder . build ( url ) ; } catch ( JDOMException e ) { throw new IOException ( e . getMessage ( ) ) ; } if ( debugXML ) System . out . println ( " SAXBuilder done" ) ; return readXML ( doc , errlog , ncmlLocation ) ; }


Input:
Replace any char not alphanumeric or in allowChars by replaceChar . [CODESPLIT] static public String allow ( String x , String allowChars , char replaceChar ) { boolean ok = true ; for ( int pos = 0 ; pos < x . length ( ) ; pos ++ ) { char c = x . charAt ( pos ) ; if ( ! ( Character . isLetterOrDigit ( c ) || ( 0 <= allowChars . indexOf ( c ) ) ) ) { ok = false ; break ; } } if ( ok ) return x ; // gotta do it
 StringBuilder sb = new StringBuilder ( x ) ; for ( int pos = 0 ; pos < sb . length ( ) ; pos ++ ) { char c = sb . charAt ( pos ) ; if ( Character . isLetterOrDigit ( c ) || ( 0 <= allowChars . indexOf ( c ) ) ) { continue ; } sb . setCharAt ( pos , replaceChar ) ; } return sb . toString ( ) ; }


Input: Break the given text into lines respecting word boundaries ( blank space ) . [CODESPLIT] public static String breakTextAtWords ( String text , String insert , int lineSize ) { StringBuilder buff = new StringBuilder ( ) ; StringTokenizer stoker = new StringTokenizer ( text ) ; int lineCount = 0 ; while ( stoker . hasMoreTokens ( ) ) { String tok = stoker . nextToken ( ) ; if ( tok . length ( ) + lineCount >= lineSize ) { buff . append ( insert ) ; lineCount = 0 ; } buff . append ( tok ) ; buff . append ( " " ) ; lineCount += tok . length ( ) + 1 ; } return buff . toString ( ) ; }


Input: Delete any non - printable characters [CODESPLIT] public static String cleanup ( byte [ ] h ) { byte [ ] bb = new byte [ h . length ] ; int count = 0 ; for ( byte b : h ) { if ( b >= 32 && b < 127 ) bb [ count ++ ] = b ; } return new String ( bb , 0 , count , CDM . utf8Charset ) ; }


Input:
Remove any char not alphanumeric or in okChars . [CODESPLIT] static public String filter ( String x , String okChars ) { boolean ok = true ; for ( int pos = 0 ; pos < x . length ( ) ; pos ++ ) { char c = x . charAt ( pos ) ; if ( ! ( Character . isLetterOrDigit ( c ) || ( 0 <= okChars . indexOf ( c ) ) ) ) { ok = false ; break ; } } if ( ok ) { return x ; } // gotta do it
 StringBuilder sb = new StringBuilder ( x . length ( ) ) ; for ( int pos = 0 ; pos < x . length ( ) ; pos ++ ) { char c = x . charAt ( pos ) ; if ( Character . isLetterOrDigit ( c ) || ( 0 <= okChars . indexOf ( c ) ) ) { sb . append ( c ) ; } } return sb . toString ( ) ; }


Input: Remove all but printable ascii [CODESPLIT] static public String filter7bits ( String s ) { if ( s == null ) return null ; char [ ] bo = new char [ s . length ( ) ] ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( ( c < 128 ) && ( c > 31 ) || ( ( c == ' ' ) || ( c == ' ' ) ) ) { bo [ count ++ ] = c ; } } return new String ( bo , 0 , count ) ; }


Input:
transform embedded space to _ [CODESPLIT] static public String makeValidCdmObjectName ( String name ) { name = name . trim ( ) ; // common case no change
 boolean ok = true ; for ( int i = 0 ; i < name . length ( ) ; i ++ ) { int c = name . charAt ( i ) ; if ( c < 0x20 ) ok = false ; if ( c == ' ' ) ok = false ; if ( c == ' ' ) ok = false ; if ( ! ok ) break ; } if ( ok ) return name ; StringBuilder sbuff = new StringBuilder ( name . length ( ) ) ; for ( int i = 0 , len = name . length ( ) ; i < len ; i ++ ) { int c = name . charAt ( i ) ; if ( ( c == ' ' ) || ( c == ' ' ) ) sbuff . append ( ' ' ) ; else if ( c >= 0x20 ) sbuff . append ( ( char ) c ) ; } return sbuff . toString ( ) ; }


Input: Count number of chars that match in two strings starting from front . [CODESPLIT] static public int match ( String s1 , String s2 ) { int i = 0 ; while ( ( i < s1 . length ( ) ) && ( i < s2 . length ( ) ) ) { if ( s1 . charAt ( i ) != s2 . charAt ( i ) ) { break ; } i ++ ; } return i ; }


Input: Pad the given string with padString on the left up to the given length . [CODESPLIT] public static String padLeft ( String s , int desiredLength , String padString ) { while ( s . length ( ) < desiredLength ) { s = padString + s ; } return s ; }


Input: Pad the given string with padString on the right up to the given length . [CODESPLIT] public static String padRight ( String s , int desiredLength , String padString ) { StringBuilder ret = new StringBuilder ( s ) ; while ( ret . length ( ) < desiredLength ) { ret . append ( padString ) ; } return ret . toString ( ) ; }


Input: Remove all occurrences of the substring sub in the string s . [CODESPLIT] static public String remove ( String s , String sub ) { int len = sub . length ( ) ; int pos ; while ( 0 <= ( pos = s . indexOf ( sub ) ) ) { s = s . substring ( 0 , pos ) + s . substring ( pos + len ) ; } return s ; }


Input:
Remove all occurrences of the character c in the string s . [CODESPLIT] static public String remove ( String s , int c ) { if ( 0 > s . indexOf ( c ) ) { // none
 return s ; } StringBuilder buff = new StringBuilder ( s ) ; int i = 0 ; while ( i < buff . length ( ) ) { if ( buff . charAt ( i ) == c ) { buff . deleteCharAt ( i ) ; } else { i ++ ; } } return buff . toString ( ) ; }


Input:
Remove all occurrences of the character c at the end of s . [CODESPLIT] static public String removeFromEnd ( String s , int c ) { if ( 0 > s . indexOf ( c ) ) // none
 return s ; int len = s . length ( ) ; while ( ( s . charAt ( len - 1 ) == c ) && ( len > 0 ) ) len -- ; if ( len == s . length ( ) ) return s ; return s . substring ( 0 , len ) ; }


Input: Remove any whitespace ( ie . Character . isWhitespace ) from the input string . [CODESPLIT] public static String removeWhitespace ( String inputString ) { StringBuilder sb = new StringBuilder ( ) ; char [ ] chars = inputString . toCharArray ( ) ; for ( char c : chars ) { if ( Character . isWhitespace ( c ) ) { continue ; } sb . append ( c ) ; } return sb . toString ( ) ; }


Input:
Collapse continuous whitespace into one single . [CODESPLIT] static public String collapseWhitespace ( String s ) { int len = s . length ( ) ; StringBuilder b = new StringBuilder ( len ) ; for ( int i = 0 ; i < len ; i ++ ) { char c = s . charAt ( i ) ; if ( ! Character . isWhitespace ( c ) ) { b . append ( c ) ; } else { b . append ( ' ' ) ; while ( ( i + 1 < len ) && Character . isWhitespace ( s . charAt ( i + 1 ) ) ) { i ++ ; /// skip further whitespace
 } } } return b . toString ( ) ; }


Input:
Replace any char out in s with in . [CODESPLIT] static public String replace ( String s , char out , String in ) { if ( s . indexOf ( out ) < 0 ) { return s ; } // gotta do it
 StringBuilder sb = new StringBuilder ( s ) ; replace ( sb , out , in ) ; return sb . toString ( ) ; }


Input:
Replace all occurrences of any char in replaceChar with corresponding String in replaceWith [CODESPLIT] static public String replace ( String x , char [ ] replaceChar , String [ ] replaceWith ) { // common case no replacement
 boolean ok = true ; for ( char aReplaceChar : replaceChar ) { int pos = x . indexOf ( aReplaceChar ) ; ok = ( pos < 0 ) ; if ( ! ok ) break ; } if ( ok ) return x ; // gotta do it
 StringBuilder sb = new StringBuilder ( x ) ; for ( int i = 0 ; i < replaceChar . length ; i ++ ) { int pos = x . indexOf ( replaceChar [ i ] ) ; if ( pos >= 0 ) { replace ( sb , replaceChar [ i ] , replaceWith [ i ] ) ; } } return sb . toString ( ) ; }


Input:
Replaces all occurrences of pattern in string with value [CODESPLIT] public static String replace ( String string , String pattern , String value ) { if ( pattern . length ( ) == 0 ) return string ; if ( ! string . contains ( pattern ) ) return string ; // ok gotta do it
 StringBuilder returnValue = new StringBuilder ( ) ; int patternLength = pattern . length ( ) ; while ( true ) { int idx = string . indexOf ( pattern ) ; if ( idx < 0 ) break ; returnValue . append ( string . substring ( 0 , idx ) ) ; if ( value != null ) returnValue . append ( value ) ; string = string . substring ( idx + patternLength ) ; } returnValue . append ( string ) ; return returnValue . toString ( ) ; }


Input:
Replace all occurrences of orgReplace with orgChar ; inverse of replace () . [CODESPLIT] static public String unreplace ( String x , String [ ] orgReplace , char [ ] orgChar ) { // common case no replacement
 boolean ok = true ; for ( String anOrgReplace : orgReplace ) { int pos = x . indexOf ( anOrgReplace ) ; ok = ( pos < 0 ) ; if ( ! ok ) break ; } if ( ok ) return x ; // gotta do it
 StringBuilder result = new StringBuilder ( x ) ; for ( int i = 0 ; i < orgReplace . length ; i ++ ) { int pos = result . indexOf ( orgReplace [ i ] ) ; if ( pos >= 0 ) { unreplace ( result , orgReplace [ i ] , orgChar [ i ] ) ; } } return result . toString ( ) ; }


Input: Find all occurrences of the match in original and substitute the subst string . [CODESPLIT] static public String substitute ( String original , String match , String subst ) { String s = original ; int pos ; while ( 0 <= ( pos = s . indexOf ( match ) ) ) { StringBuilder sb = new StringBuilder ( s ) ; s = sb . replace ( pos , pos + match . length ( ) , subst ) . toString ( ) ; } return s ; }


Input: Escape any char not alphanumeric or in okChars . Escape by replacing char with %xx ( hex ) . [CODESPLIT] static public String escape ( String x , String okChars ) { StringBuilder newname = new StringBuilder ( ) ; for ( char c : x . toCharArray ( ) ) { if ( c == ' ' ) { newname . append ( "%%" ) ; } else if ( ! Character . isLetterOrDigit ( c ) && okChars . indexOf ( c ) < 0 ) { newname . append ( ' ' ) ; newname . append ( Integer . toHexString ( ( 0xFF & ( int ) c ) ) ) ; } else newname . append ( c ) ; } return newname . toString ( ) ; }


Input:
This finds any %xx and converts to the equivalent char . Inverse of escape () . [CODESPLIT] static public String unescape ( String x ) { if ( x . indexOf ( ' ' ) < 0 ) { return x ; } // gotta do it
 char [ ] b = new char [ 2 ] ; StringBuilder sb = new StringBuilder ( x ) ; for ( int pos = 0 ; pos < sb . length ( ) ; pos ++ ) { char c = sb . charAt ( pos ) ; if ( c != ' ' ) { continue ; } if ( pos >= sb . length ( ) - 2 ) { // malformed - should be %xx
 return x ; } b [ 0 ] = sb . charAt ( pos + 1 ) ; b [ 1 ] = sb . charAt ( pos + 2 ) ; int value ; try { value = Integer . parseInt ( new String ( b ) , 16 ) ; } catch ( NumberFormatException e ) { continue ; // not a hex number
 } c = ( char ) value ; sb . setCharAt ( pos , c ) ; sb . delete ( pos + 1 , pos + 3 ) ; } return sb . toString ( ) ; }


Input:
Find all occurences of match strings in original and substitute the corresponding subst string . [CODESPLIT] static public String substitute ( String original , String [ ] match , String [ ] subst ) { boolean ok = true ; for ( String aMatch : match ) { if ( original . contains ( aMatch ) ) { ok = false ; break ; } } if ( ok ) { return original ; } // gotta do it;
 StringBuilder sb = new StringBuilder ( original ) ; for ( int i = 0 ; i < match . length ; i ++ ) { substitute ( sb , match [ i ] , subst [ i ] ) ; } return sb . toString ( ) ; }


Input: Remove any of the characters in out from sb [CODESPLIT] static public void remove ( StringBuilder sb , String out ) { int i = 0 ; while ( i < sb . length ( ) ) { int c = sb . charAt ( i ) ; boolean ok = true ; for ( int j = 0 ; j < out . length ( ) ; j ++ ) { if ( out . charAt ( j ) == c ) { sb . delete ( i , i + 1 ) ; ok = false ; break ; } } if ( ok ) i ++ ; } }


Input: Replace any String out in sb with char in . [CODESPLIT] static public void unreplace ( StringBuilder sb , String out , char in ) { int pos ; while ( 0 <= ( pos = sb . indexOf ( out ) ) ) { sb . setCharAt ( pos , in ) ; sb . delete ( pos + 1 , pos + out . length ( ) ) ; } }


Input: Replace any of the characters from out with corresponding character from in [CODESPLIT] static public void replace ( StringBuilder sb , String out , String in ) { for ( int i = 0 ; i < sb . length ( ) ; i ++ ) { int c = sb . charAt ( i ) ; for ( int j = 0 ; j < out . length ( ) ; j ++ ) { if ( out . charAt ( j ) == c ) sb . setCharAt ( i , in . charAt ( j ) ) ; } } }


Input:
Find all occurences of the match in original and substitute the subst string directly into the original . [CODESPLIT] static public void substitute ( StringBuilder sbuff , String match , String subst ) { int pos , fromIndex = 0 ; int substLen = subst . length ( ) ; int matchLen = match . length ( ) ; while ( 0 <= ( pos = sbuff . indexOf ( match , fromIndex ) ) ) { sbuff . replace ( pos , pos + matchLen , subst ) ; fromIndex = pos + substLen ; // make sure dont get into an infinite loop
 } }


Input: Remove bad char from beginning or end of string [CODESPLIT] static public String trim ( String s , int bad ) { int len = s . length ( ) ; int st = 0 ; while ( ( st < len ) && ( s . charAt ( st ) == bad ) ) { st ++ ; } while ( ( st < len ) && ( s . charAt ( len - 1 ) == bad ) ) { len -- ; } return ( ( st > 0 ) || ( len < s . length ( ) ) ) ? s . substring ( st , len ) : s ; }


Input: old school : used by FMRC and Point [CODESPLIT] protected void makeCollection ( ) { Formatter errlog = new Formatter ( ) ; datasetCollection = new MFileCollectionManager ( config , errlog , logger ) ; topDirectory = datasetCollection . getRoot ( ) ; String errs = errlog . toString ( ) ; if ( errs . length ( ) > 0 ) logger . warn ( "MFileCollectionManager parse error = {} " , errs ) ; }


Input: called by eventBus this is where the trigger comes in [CODESPLIT] @ Subscribe public void processEvent ( CollectionUpdateEvent event ) { if ( ! config . collectionName . equals ( event . getCollectionName ( ) ) ) return ; // not for me try { update ( event . getType ( ) ) ; } catch ( IOException e ) { logger . error ( "Error processing event" , e ) ; } }


Input: ///////////////////////////////////////////////// [CODESPLIT] public void showStatus ( Formatter f ) { try { checkState ( ) ; _showStatus ( f , false , null ) ; } catch ( Throwable t ) { StringWriter sw = new StringWriter ( 5000 ) ; t . printStackTrace ( new PrintWriter ( sw ) ) ; f . format ( sw . toString ( ) ) ; } }


Input: A request has come in check that the state has been initialized . this is called from the request thread . [CODESPLIT] protected State checkState ( ) throws IOException { State localState ; synchronized ( lock ) { if ( first ) { firstInit ( ) ; updateCollection ( state , config . updateConfig . updateType ) ; // makeDatasetTop(state); first = false ; } localState = state . copy ( ) ; } return localState ; }


Input: Collection was changed update internal objects . called by CollectionUpdater trigger via handleCollectionEvent so in a quartz scheduler thread [CODESPLIT] protected void update ( CollectionUpdateType force ) throws IOException { // this may be called from a background thread, or from checkState() request thread State localState ; synchronized ( lock ) { if ( first ) { state = checkState ( ) ; state . lastInvChange = System . currentTimeMillis ( ) ; return ; } // do the update in a local object localState = state . copy ( ) ; } updateCollection ( localState , force ) ; // makeDatasetTop(localState); localState . lastInvChange = System . currentTimeMillis ( ) ; // switch to live synchronized ( lock ) { state = localState ; } }


Input: ///////////////////////////////////////////////////////////////////////////////////////////////// [CODESPLIT] protected String makeFullName ( DatasetNode ds ) { if ( ds . getParent ( ) == null ) return ds . getName ( ) ; String parentName = makeFullName ( ds . getParent ( ) ) ; if ( parentName == null || parentName . length ( ) == 0 ) return ds . getName ( ) ; return parentName + "/" + ds . getName ( ) ; }


Input: Make the containing catalog of this feature collection http : // server : port / thredds / catalog / path / catalog . xml [CODESPLIT] protected CatalogBuilder makeCatalogTop ( URI catURI , State localState ) throws IOException , URISyntaxException { Catalog parentCatalog = parent . getParentCatalog ( ) ; CatalogBuilder topCatalog = new CatalogBuilder ( ) ; topCatalog . setName ( makeFullName ( parent ) ) ; topCatalog . setVersion ( parentCatalog . getVersion ( ) ) ; topCatalog . setBaseURI ( catURI ) ; DatasetBuilder top = makeDatasetTop ( catURI , localState ) ; topCatalog . addDataset ( top ) ; // topCatalog.addService(StandardServices.latest.getService());  // in case its needed topCatalog . addService ( virtualService ) ; return topCatalog ; }


Input: this catalog lists the individual files comprising the collection . [CODESPLIT] protected CatalogBuilder makeCatalogFiles ( URI catURI , State localState , List < String > filenames , boolean addLatest ) throws IOException { Catalog parentCatalog = parent . getParentCatalog ( ) ; CatalogBuilder result = new CatalogBuilder ( ) ; result . setName ( makeFullName ( parent ) ) ; result . setVersion ( parentCatalog . getVersion ( ) ) ; result . setBaseURI ( catURI ) ; result . addService ( orgService ) ; DatasetBuilder top = new DatasetBuilder ( null ) ; top . transferInheritedMetadata ( parent ) ; // make all inherited metadata local top . setName ( FILES ) ; // add Variables, GeospatialCoverage, TimeCoverage ThreddsMetadata tmi = top . getInheritableMetadata ( ) ; tmi . set ( Dataset . TimeCoverage , null ) ; // LOOK if ( localState . coverage != null ) { tmi . set ( Dataset . GeospatialCoverage , localState . coverage ) ; } tmi . set ( Dataset . ServiceName , orgService . getName ( ) ) ; result . addDataset ( top ) ; if ( addLatest ) { DatasetBuilder latest = new DatasetBuilder ( top ) ; latest . setName ( getLatestFileName ( ) ) ; latest . put ( Dataset . UrlPath , LATEST_DATASET_CATALOG ) ; latest . put ( Dataset . Id , LATEST_DATASET_CATALOG ) ; latest . put ( Dataset . ServiceName , latestService . getName ( ) ) ; latest . addServiceToCatalog ( latestService ) ; top . addDataset ( latest ) ; } // sort copy of files List < String > sortedFilenames = new ArrayList <> ( filenames ) ; Collections . sort ( sortedFilenames , String . CASE_INSENSITIVE_ORDER ) ; // if not increasing (i.e. we WANT newest file listed first), reverse sort if ( ! this . config . getSortFilesAscending ( ) ) { Collections . reverse ( sortedFilenames ) ; } for ( String f : sortedFilenames ) { if ( ! f . startsWith ( topDirectory ) ) logger . warn ( "File {} doesnt start with topDir {}" , f , topDirectory ) ; DatasetBuilder ds = new DatasetBuilder ( top ) ; String fname = f . substring ( topDirectory . length ( ) + 1 ) ; ds . setName ( fname ) ; String lpath = this . configPath + "/" + FILES + "/" + fname ; // String lpath = getPath() + "/" + FILES + "/" + fname; ds . put ( Dataset . UrlPath , lpath ) ; ds . put ( Dataset . Id , lpath ) ; ds . put ( Dataset . VariableMapLinkURI , new ThreddsMetadata . UriResolved ( makeMetadataLink ( lpath , VARIABLES ) , catURI ) ) ; File file = new File ( f ) ; ds . put ( Dataset . DataSize , file . length ( ) ) ; top . addDataset ( ds ) ; } return result ; }


Input: Get the associated Grid Dataset if any . called by DatasetHandler . openGridDataset () [CODESPLIT] public ucar . nc2 . dt . grid . GridDataset getGridDataset ( String matchPath ) throws IOException { return null ; }


Input: Get the dataset named by the path . called by DatasetHandler . getNetcdfFile () [CODESPLIT] public NetcdfDataset getNetcdfDataset ( String matchPath ) throws IOException { int pos = matchPath . indexOf ( ' ' ) ; String type = ( pos > - 1 ) ? matchPath . substring ( 0 , pos ) : matchPath ; String name = ( pos > - 1 ) ? matchPath . substring ( pos + 1 ) : "" ; // this assumes that these are files. also might be remote datasets from a catalog if ( type . equalsIgnoreCase ( FILES ) ) { if ( topDirectory == null ) return null ; String filename = new StringBuilder ( topDirectory ) . append ( topDirectory . endsWith ( "/" ) ? "" : "/" ) . append ( name ) . toString ( ) ; DatasetUrl durl = new DatasetUrl ( null , filename ) ; return NetcdfDataset . acquireDataset ( null , durl , null , - 1 , null , null ) ; // no enhancement } GridDataset gds = getGridDataset ( matchPath ) ; // LOOK cant be right return ( gds == null ) ? null : ( NetcdfDataset ) gds . getNetcdfFile ( ) ; }


Input: this says that a File URL has to be topDirectory + [ FILES / + ] + match . remaining [CODESPLIT] public File getFile ( String remaining ) { if ( null == topDirectory ) return null ; int pos = remaining . indexOf ( FILES ) ; StringBuilder fname = new StringBuilder ( topDirectory ) ; if ( ! topDirectory . endsWith ( "/" ) ) fname . append ( "/" ) ; fname . append ( ( pos > - 1 ) ? remaining . substring ( pos + FILES . length ( ) + 1 ) : remaining ) ; return new File ( fname . toString ( ) ) ; }


Input:
/ * http : // www . unidata . ucar . edu / software / netcdf / docs / BestPractices . html Packed Data Values [CODESPLIT] private void doCopyCompress ( Formatter f , ucar . nc2 . grib . grib2 . Grib2Record gr , RandomAccessFile raf , OutputStream out , Counters counters ) throws IOException { float [ ] data = gr . readData ( raf ) ; Grib2SectionDataRepresentation drss = gr . getDataRepresentationSection ( ) ; drss . getDrs ( raf ) ; // calc scale/offset GribData . Info info = gr . getBinaryDataInfo ( raf ) ; int nbits = info . numberOfBits ; counters . count ( "Nbits" , nbits ) ; int width = ( 2 << ( nbits - 1 ) ) - 1 ; //f.format(" nbits = %d%n", nbits); //f.format(" width = %d (0x%s) %n", width2, Long.toHexString(width2)); float dataMin = Float . MAX_VALUE ; float dataMax = - Float . MAX_VALUE ; for ( float fd : data ) { dataMin = Math . min ( dataMin , fd ) ; dataMax = Math . max ( dataMax , fd ) ; } //f.format(" dataMin = %f%n", dataMin); //f.format(" dataMax = %f%n", dataMax); // f.format(" range = %f%n", (dataMax - dataMin)); // scale_factor =(dataMax - dataMin) / (2^n - 1) // add_offset = dataMin + 2^(n-1) * scale_factor //float scale_factor = (dataMax - dataMin) / width2; //float add_offset = dataMin + width2 * scale_factor / 2; float scale_factor = ( dataMax - dataMin ) / ( width - 2 ) ; float add_offset = dataMin - scale_factor ; //f.format(" scale_factor = %f%n", scale_factor); //f.format(" add_offset = %f%n", add_offset); // unpacked_data_value = packed_data_value * scale_factor + add_offset // packed_data_value = nint((unpacked_data_value - add_offset) / scale_factor) /* compressedSize = out.size();
      f.format(" compressedSize = %d%n", compressedSize);
      f.format(" compressedRatio = %f%n", (float) compressedSize / (n*nbits/8));
      f.format(" ratio with grib = %f%n", (float) compressedSize / bean1.getDataLength());  */ }


Input: ///////////////////////////////////////////// [CODESPLIT] private void doCheckTables ( Formatter f , MCollection dcm , boolean useIndex ) throws IOException { f . format ( "Check Grib-2 Parameter Tables%n" ) ; int [ ] accum = new int [ 4 ] ; for ( MFile mfile : dcm . getFilesSorted ( ) ) { f . format ( "%n %s%n" , mfile . getPath ( ) ) ; doCheckTables ( mfile , f , accum ) ; } f . format ( "%nGrand total=%d not operational = %d local = %d missing = %d%n" , accum [ 0 ] , accum [ 1 ] , accum [ 2 ] , accum [ 3 ] ) ; }


Input: ///////////////////////////////////////////// [CODESPLIT] private void doLocalUseSection ( Formatter f , MCollection dcm , boolean useIndex ) throws IOException { f . format ( "Show Local Use Section%n" ) ; for ( MFile mfile : dcm . getFilesSorted ( ) ) { f . format ( " %s%n" , mfile . getPath ( ) ) ; doLocalUseSection ( mfile , f , useIndex ) ; } }


Input: Look through the collection and find what GDS and PDS templates are used . [CODESPLIT] private void doUniqueTemplates ( Formatter f , MCollection dcm , boolean useIndex ) throws IOException { f . format ( "Show Unique GDS and PDS templates%n" ) ; Map < Integer , FileList > gdsSet = new HashMap <> ( ) ; Map < Integer , FileList > pdsSet = new HashMap <> ( ) ; Map < Integer , FileList > drsSet = new HashMap <> ( ) ; for ( MFile mfile : dcm . getFilesSorted ( ) ) { f . format ( " %s%n" , mfile . getPath ( ) ) ; doUniqueTemplates ( mfile , gdsSet , pdsSet , drsSet , f ) ; } List < FileList > sorted = new ArrayList <> ( gdsSet . values ( ) ) ; Collections . sort ( sorted ) ; for ( FileList gdsl : sorted ) { f . format ( "%nGDS %s template= %d %n" , gdsl . name , gdsl . template ) ; for ( FileCount fc : gdsl . fileList ) { f . format ( "  %5d %s %n" , fc . countRecords , fc . f . getPath ( ) ) ; } } List < FileList > sortedPds = new ArrayList <> ( pdsSet . values ( ) ) ; Collections . sort ( sortedPds ) ; for ( FileList pdsl : sortedPds ) { f . format ( "%n===================================================%n" ) ; f . format ( "%nPDS %s template= %d %n" , pdsl . name , pdsl . template ) ; for ( FileCount fc : pdsl . fileList ) { f . format ( "  %5d %s %n" , fc . countRecords , fc . f . getPath ( ) ) ; } } List < FileList > sortedDrs = new ArrayList <> ( drsSet . values ( ) ) ; Collections . sort ( sortedDrs ) ; for ( FileList pdsl : sortedDrs ) { f . format ( "%n===================================================%n" ) ; f . format ( "%nDRS %s template= %d %n" , pdsl . name , pdsl . template ) ; for ( FileCount fc : pdsl . fileList ) { f . format ( "  %5d %s %n" , fc . countRecords , fc . f . getPath ( ) ) ; } } }


Input: ///////////////////////////////////////////////// [CODESPLIT] private void doPdsSummary ( Formatter f , MCollection dcm , boolean eachFile ) throws IOException { Counters countersAll = new Counters ( ) ; countersAll . add ( "template" ) ; countersAll . add ( "timeUnit" ) ; countersAll . add ( "timeOffset" ) ; countersAll . add ( "timeIntervalSize" ) ; countersAll . add ( "levelType" ) ; countersAll . add ( "genProcessType" ) ; countersAll . add ( "genProcessId" ) ; countersAll . add ( "levelScale" ) ; countersAll . add ( "nExtraCoords" ) ; for ( MFile mfile : dcm . getFilesSorted ( ) ) { f . format ( "---%s%n" , mfile . getPath ( ) ) ; doPdsSummary ( f , mfile , countersAll ) ; if ( eachFile ) { countersAll . show ( f ) ; countersAll . reset ( ) ; } } f . format ( "PdsSummary - all files%n" ) ; if ( ! eachFile ) countersAll . show ( f ) ; }


Input: ///////////////////////////////////////////// [CODESPLIT] private void doIdProblems ( Formatter f , MCollection dcm , boolean useIndex ) throws IOException { f . format ( "Look for ID Problems%n" ) ; Counters countersAll = new Counters ( ) ; countersAll . add ( "discipline" ) ; countersAll . add ( "masterTable" ) ; countersAll . add ( "localTable" ) ; countersAll . add ( "centerId" ) ; countersAll . add ( "subcenterId" ) ; countersAll . add ( "genProcess" ) ; countersAll . add ( "backProcess" ) ; countersAll . add ( "significanceOfReference" ) ; for ( MFile mfile : dcm . getFilesSorted ( ) ) { f . format ( " %s%n" , mfile . getPath ( ) ) ; doIdProblems ( f , mfile , useIndex , countersAll ) ; } countersAll . show ( f ) ; }


Input: ///////////////////////////////////////////// [CODESPLIT] private void doDrsSummary ( Formatter f , MCollection dcm , boolean useIndex , boolean eachFile , boolean extra ) throws IOException { f . format ( "Show Unique DRS Templates%n" ) ; Counters countersAll = new Counters ( ) ; countersAll . add ( "DRS_template" ) ; countersAll . add ( "BMS indicator" ) ; countersAll . add ( "DRS template 40 signed problem" ) ; countersAll . add ( "Number_of_Bits" ) ; for ( MFile mfile : dcm . getFilesSorted ( ) ) { f . format ( "------- %s%n" , mfile . getPath ( ) ) ; if ( useIndex ) doDrsSummaryIndex ( f , mfile , extra , countersAll ) ; else doDrsSummaryScan ( f , mfile , extra , countersAll ) ; if ( eachFile ) { countersAll . show ( f ) ; f . format ( "%n" ) ; countersAll . reset ( ) ; } } if ( ! eachFile ) countersAll . show ( f ) ; }


Input: ///////////////////////////////////////////// [CODESPLIT] private void doGdsSummary ( Formatter f , MCollection dcm , boolean extra ) throws IOException { f . format ( "Show Unique GDS Templates%n" ) ; Counters counters = new Counters ( ) ; counters . add ( "template" ) ; counters . add ( "scanMode" ) ; counters . add ( "scanModeDifference" ) ; for ( MFile mfile : dcm . getFilesSorted ( ) ) { f . format ( " %s%n" , mfile . getPath ( ) ) ; doGdsSummary ( f , mfile , counters , extra ) ; } counters . show ( f ) ; }


Input: ///////////////////////////////////////////////////////////////// [CODESPLIT] private void doTimeCoord ( Formatter f , MCollection dcm , boolean useIndex ) throws IOException { Counters counters = new Counters ( ) ; counters . add ( "template" ) ; counters . add ( "timeUnit" ) ; counters . add ( "statType" ) ; counters . add ( "NumberTimeIntervals" ) ; counters . add ( "TimeIntervalsDiffer" ) ; counters . add ( "TimeIntervalsLength" ) ; int count = 0 ; for ( MFile mfile : dcm . getFilesSorted ( ) ) { f . format ( " %s%n" , mfile . getPath ( ) ) ; count += doTimeCoord ( f , mfile , counters ) ; } f . format ( "total records = %d%n" , count ) ; counters . show ( f ) ; }


Input:
///////////////////////////////////////////////////////////////////////////////// [CODESPLIT] private void doRename ( Formatter f , MCollection dcm , boolean useIndex ) throws IOException { f . format ( "CHECK Grib-2 Names: Old vs New for collection %s%n" , dcm . getCollectionName ( ) ) ; List < VarName > varNames = new ArrayList <> ( 3000 ) ; Map < String , List < String > > gridsAll = new HashMap <> ( 1000 ) ; // old -> list<new> int countExactMatch = 0 ; int countExactMatchIg = 0 ; int countOldVars = 0 ; for ( MFile mfile : dcm . getFilesSorted ( ) ) { f . format ( "%n%s%n" , mfile . getPath ( ) ) ; Map < Integer , GridMatch > gridsNew = getGridsNew ( mfile , f ) ; Map < Integer , GridMatch > gridsOld = getGridsOld ( mfile , f ) ; // look for exact match on name Set < String > namesNew = new HashSet <> ( gridsNew . size ( ) ) ; for ( GridMatch gm : gridsNew . values ( ) ) namesNew . ( gm . grid . getFullName ( ) ) ; for ( GridMatch gm : gridsOld . values ( ) ) { if ( namesNew . contains ( gm . grid . getFullName ( ) ) ) countExactMatch ++ ; countOldVars ++ ; } // look for exact match on hashcode for ( GridMatch gm : gridsNew . values ( ) ) { GridMatch match = gridsOld . get ( gm . hashCode ( ) ) ; if ( match != null ) { gm . match = match ; match . match = gm ; } } // look for alternative match for ( GridMatch gm : gridsNew . values ( ) ) { if ( gm . match == null ) { GridMatch match = altMatch ( gm , gridsOld . values ( ) ) ; if ( match != null ) { gm . match = match ; match . match = gm ; } } } // print out match f . format ( "%n" ) ; List < GridMatch > listNew = new ArrayList <> ( gridsNew . values ( ) ) ; Collections . sort ( listNew ) ; for ( GridMatch gm : listNew ) { f . format ( " %s%n" , gm . grid . findAttributeIgnoreCase ( Grib . VARIABLE_ID_ATTNAME ) ) ; f . format ( " %s (%d)%n" , gm . grid . getFullName ( ) , gm . hashCode ( ) ) ; if ( gm . match != null ) { boolean exact = gm . match . grid . getFullName ( ) . equals ( gm . grid . getFullName ( ) ) ; boolean exactIg = ! exact && gm . match . grid . getFullName ( ) . equalsIgnoreCase ( gm . grid . getFullName ( ) ) ; if ( exactIg ) countExactMatchIg ++ ; String status = exact ? " " : exactIg ? "**" : " *" ; f . format ( "%s%s (%d)%n" , status , gm . match . grid . getFullName ( ) , gm . match . hashCode ( ) ) ; } f . format ( "%n" ) ; } // print out missing f . format ( "%nMISSING MATCHES IN NEW%n" ) ; List < GridMatch > list = new ArrayList <> ( gridsNew . values ( ) ) ; Collections . sort ( list ) ; for ( GridMatch gm : list ) { if ( gm . match == null ) f . format ( " %s (%s) == %s%n" , gm . grid . getFullName ( ) , gm . show ( ) , gm . grid . getDescription ( ) ) ; } f . format ( "%nMISSING MATCHES IN OLD%n" ) ; List < GridMatch > listOld = new ArrayList <> ( gridsOld . values ( ) ) ; Collections . sort ( listOld ) ; for ( GridMatch gm : listOld ) { if ( gm . match == null ) f . format ( " %s (%s)%n" , gm . grid . getFullName ( ) , gm . show ( ) ) ; } // add to gridsAll to track old -> new mapping for ( GridMatch gmOld : listOld ) { String key = gmOld . grid . getShortName ( ) ; List < String > newGrids = gridsAll . get ( key ) ; if ( newGrids == null ) { newGrids = new ArrayList <> ( ) ; gridsAll . put ( key , newGrids ) ; } if ( gmOld . match != null ) { String keyNew = gmOld . match . grid . getShortName ( ) ; if ( ! newGrids . contains ( keyNew ) ) newGrids . add ( keyNew ) ; } } // add matches to VarNames for ( GridMatch gmOld : listOld ) { if ( gmOld . match == null ) { f . format ( "MISSING %s (%s)%n" , gmOld . grid . getFullName ( ) , gmOld . show ( ) ) ; continue ; } Attribute att = gmOld . match . grid . findAttributeIgnoreCase ( Grib . VARIABLE_ID_ATTNAME ) ; String varId = att == null ? "" : att . getStringValue ( ) ; varNames . add ( new VarName ( mfile . getName ( ) , gmOld . grid . getShortName ( ) , gmOld . match . grid . getShortName ( ) , varId ) ) ; } } // show old -> new mapping f . format ( "%nOLD -> NEW MAPPINGS%n" ) ; List < String > keys = new ArrayList <> ( gridsAll . keySet ( ) ) ; int total = keys . size ( ) ; int dups = 0 ; Collections . sort ( keys ) ; for ( String key : keys ) { f . format ( " OLD %s%n" , key ) ; List < String > newGrids = gridsAll . get ( key ) ; Collections . sort ( newGrids ) ; if ( newGrids . size ( ) > 1 ) dups ++ ; for ( String newKey : newGrids ) f . format ( " NEW %s%n" , newKey ) ; . format ( "%n" ) ; } . format ( "Exact matches=%d  Exact ignore case=%d  totalOldVars=%d%n" , countExactMatch , countExactMatchIg , countOldVars ) ; . format ( "Number with more than one map=%d total=%d%n" , dups , total ) ; // old -> new mapping xml table if ( ! useIndex ) { Element rootElem = new Element ( "gribVarMap" ) ; Document doc = new Document ( rootElem ) ; rootElem . setAttribute ( "collection" , dcm . getCollectionName ( ) ) ; String currentDs = null ; Element dsElem = null ; for ( VarName vn : varNames ) { if ( ! vn . dataset . equals ( currentDs ) ) { dsElem = new Element ( "dataset" ) ; rootElem . addContent ( dsElem ) ; dsElem . setAttribute ( "name" , vn . dataset ) ; currentDs = vn . dataset ; } Element param = new Element ( "param" ) ; dsElem . addContent ( param ) ; param . setAttribute ( "oldName" , vn . oldVar ) ; param . setAttribute ( "newName" , vn . newVar ) ; param . setAttribute ( "varId" , vn . varId ) ; } FileOutputStream fout = new FileOutputStream ( "C:/tmp/grib2VarMap.xml" ) ; XMLOutputter fmt = new XMLOutputter ( Format . getPrettyFormat ( ) ) ; fmt . output ( doc , fout ) ; fout . close ( ) ; } /*  old -> new mapping xml table
   if (!useIndex) {
     Element rootElem = new Element("gribVarMap");
     Document doc = new Document(rootElem);
     rootElem.setAttribute("collection", dcm.getCollectionName());

     for (String key : keys) {
       Element param = new Element("param");
       rootElem.addContent(param);
       param.setAttribute("oldName", key);
       List<String> newGrids = gridsAll.get(key);
       Collections.sort(newGrids);
       for (String newKey : newGrids)
         param.addContent(new Element("newName").addContent(newKey));
     }

     FileOutputStream fout = new FileOutputStream("C:/tmp/gribVarMap.xml");
     XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
     fmt.output(doc, fout);
     fout.close();
   } */ } private GridMatch altMatch  ( GridMatch want , Collection < GridMatch > test ) { // look for scale factor errors in prob for ( GridMatch gm : test ) { if ( gm . match != null ) continue ; // already matched if ( gm . altMatch ( want ) ) { //gm.altMatch(want); //debug return gm ; } } // give up matching the prob for ( GridMatch gm : test ) { if ( gm . match != null ) continue ; // already matched if ( gm . altMatchNoProb ( want ) ) { //gm.altMatchNoProb(want); // debug return gm ; } } return null ; }


Input: Get a list of all the nested datasets . [CODESPLIT] @ Override public java . util . List < InvDataset > getDatasets ( ) { read ( ) ; return useProxy ? proxy . getDatasets ( ) : super . getDatasets ( ) ; }


Input: Release resources - undo the read of the catalog . This is needed when crawling large catalogs . For modest catalogs that you will repeatedly examine do not use this method . [CODESPLIT] public void release ( ) { datasets = new java . util . ArrayList <> ( ) ; proxy = null ; useProxy = false ; init = false ; }


Input: Read the referenced catalog asynchronously if the catalog factory supports it . If it doesnt this method will work equivilently to read () which is called the first time getDatasets () is called . If the catalog is already read in the callback will be called immediately before this method exits . [CODESPLIT] public synchronized void readAsynch ( InvCatalogFactory factory , CatalogSetCallback caller ) { if ( init ) { caller . setCatalog ( ( InvCatalogImpl ) getParentCatalog ( ) ) ; return ; } // may be reletive String hrefResolved ; try { java . net . URI uri = getParentCatalog ( ) . resolveUri ( href ) ; hrefResolved = uri . toString ( ) ; } catch ( java . net . URISyntaxException e ) { // this is to display an error message proxy = new InvDatasetImpl ( null , "HREF ERROR" ) ; if ( debug ) System . out . println ( "HREF ERROR =\n  " + href + " err= " + e . getMessage ( ) ) ; proxy . addProperty ( new InvProperty ( "HREF ERROR" , href ) ) ; datasets . add ( proxy ) ; return ; } // open and read the referenced catalog XML asynchronously // setCatalog will be called when ready try { if ( debug ) System . out . println ( " InvCatalogRef readXMLasynch " + getFullName ( ) + "  hrefResolved = " + hrefResolved ) ; factory . readXMLasynch ( hrefResolved , new Callback ( caller ) ) ; } catch ( Exception e ) { // this is to display an error message proxy = new InvDatasetImpl ( null , "HREF ERROR" ) ; if ( debug ) System . out . println ( "HREF ERROR =\n  " + href + " err= " + e . getMessage ( ) ) ; proxy . addProperty ( new InvProperty ( "HREF ERROR" , href ) ) ; datasets . add ( proxy ) ; } }


Input: // proxy [CODESPLIT] @ Override public thredds . catalog . InvDatasetImpl findDatasetByName ( java . lang . String p0 ) { return ! useProxy ? super . findDatasetByName ( p0 ) : proxy . findDatasetByName ( p0 ) ; }