List of usage examples for java.util.logging Level FINER
Level FINER
To view the source code for java.util.logging Level FINER.
Click Source Link
From source file:foodsimulationmodel.pathmapping.Route.java
private synchronized static void populateCoordCache() { double time = System.nanoTime(); if (coordCache == null) { // Fist check cache has been created coordCache = new HashMap<Coordinate, List<Road>>(); LOGGER.log(Level.FINER, "Route.populateCoordCache called for first time, creating new cache of all Road coordinates."); }//from w w w .j a va 2 s .c o m if (coordCache.size() == 0) { // Now popualte it if it hasn't already // been populated LOGGER.log(Level.FINER, "Route.populateCoordCache: is empty, creating new cache of all Road coordinates."); for (Road r : ContextManager.roadContext.getObjects(Road.class)) { for (Coordinate c : ContextManager.roadProjection.getGeometry(r).getCoordinates()) { if (coordCache.containsKey(c)) { coordCache.get(c).add(r); } else { List<Road> l = new ArrayList<Road>(); l.add(r); // TODO Need to put *new* coordinate here? Not use // existing one in memory? coordCache.put(new Coordinate(c), l); } } } LOGGER.log(Level.FINER, "... finished caching all road coordinates (in " + 0.000001 * (System.nanoTime() - time) + "ms)"); } }
From source file:org.geoserver.ows.Dispatcher.java
void exception(Throwable t, Service service, Request request) { Throwable current = t;/* w w w . j ava2 s . c om*/ while (current != null && !(current instanceof ClientStreamAbortedException) && !isSecurityException(current) && !(current instanceof HttpErrorCodeException)) { if (current instanceof SAXException) current = ((SAXException) current).getException(); else current = current.getCause(); } if (current instanceof ClientStreamAbortedException) { logger.log(Level.FINER, "Client has closed stream", t); return; } if (isSecurityException(current)) { throw (RuntimeException) current; } if (current instanceof HttpErrorCodeException) { HttpErrorCodeException ece = (HttpErrorCodeException) current; int errorCode = ece.getErrorCode(); if (errorCode < 199 || errorCode > 299) { logger.log(Level.FINE, "", t); } else { logger.log(Level.FINER, "", t); } boolean isError = ece.getErrorCode() >= 400; HttpServletResponse rsp = request.getHttpResponse(); if (ece.getContentType() != null) { rsp.setContentType(ece.getContentType()); } try { if (isError) { if (ece.getMessage() != null) { rsp.sendError(ece.getErrorCode(), ece.getMessage()); } else { rsp.sendError(ece.getErrorCode()); } } else { rsp.setStatus(ece.getErrorCode()); if (ece.getMessage() != null) { rsp.getOutputStream().print(ece.getMessage()); } } if (!isError) { // gwc returns an HttpErrorCodeException for 304s // we don't want to flag these as errors for upstream filters, ie the monitoring extension t = null; } } catch (IOException e) { // means the resposne was already commited something logger.log(Level.FINER, "", t); } } else { logger.log(Level.SEVERE, "", t); //unwind the exception stack until we find one we know about Throwable cause = t; while (cause != null) { if (cause instanceof ServiceException) { break; } cause = cause.getCause(); } if (cause == null) { // did not fine a "special" exception, create a service exception by default cause = new ServiceException(t); } // at this point we're sure it'a service exception ServiceException se = (ServiceException) cause; if (cause != t) { //copy the message, code + locator, but set cause equal to root se = new ServiceException(se.getMessage(), t, se.getCode(), se.getLocator()); } handleServiceException(se, service, request); } request.error = t; }
From source file:org.aselect.server.request.handler.aselect.authentication.ApplicationBrowserHandler.java
/** * Handles the <code>request=direct_login</code> requests. <br> * <br>/*from w w w .j a v a 2 s .co m*/ * <b>Description:</b> <br> * All the requests which contains direct_login (e.g. direct_login1, direct_login2) will be handled by this function * and send to the direct authsp handler. <code>request=cross_login</code> instead. <br> * <br> * <b>Concurrency issues:</b> <br> * - <br> * <br> * <b>Preconditions:</b> <br> * A session with a <code>rid</code> should be created first using: * <ul> * <li><code>ApplicationRequestHandler.handleAuthenticateRequest()</code> * </ul> * <code>htLoginRequest</code> should contain this <code>rid</code> parameter. <br> * <br> * <b>Postconditions:</b> <br> * - <br> * * @param htServiceRequest * HashMap containing request parameters * @param servletResponse * Used to send (HTTP) information back to user * @param pwOut * Used to write information back to the user (HTML) * @throws ASelectException * the a select exception */ private void handleDirectLogin(HashMap htServiceRequest, HttpServletResponse xservletResponse, PrintWriter pwOut) throws ASelectException { String sMethod = "handleDirectLogin"; String sRid = null; // 20121024, Bauke: added udb_user_ident mechanism HashMap<String, String> hmUserIdent = new HashMap<String, String>(); String sRequest = (String) htServiceRequest.get("request"); _systemLogger.log(Level.INFO, _sModule, sMethod, "request=" + sRequest + " htServReq=" + htServiceRequest); try { sRid = (String) htServiceRequest.get("rid"); String sAuthSPId = (String) _htSessionContext.get("direct_authsp"); _systemLogger.log(Level.FINE, _sModule, sMethod, "authsp from session=" + sAuthSPId); if (sAuthSPId == null) { sAuthSPId = (String) htServiceRequest.get("authsp"); _systemLogger.log(Level.FINE, _sModule, sMethod, "authsp from request=" + sAuthSPId); if (sAuthSPId != null) { _htSessionContext.put("direct_authsp", sAuthSPId); _sessionManager.setUpdateSession(_htSessionContext, _systemLogger); // 20120401, Bauke: postpone session action } } if (sAuthSPId == null) { _systemLogger.log(Level.WARNING, _sModule, sMethod, "Missing 'direct_authsp' in session and request, rid='" + sRid + "'"); throw new ASelectException(Errors.ERROR_ASELECT_SERVER_INVALID_REQUEST); } IAuthSPDirectLoginProtocolHandler oProtocolHandler = _authspHandlerManager .getAuthSPDirectLoginProtocolHandler(sAuthSPId); _systemLogger.log(Level.INFO, _sModule, sMethod, "ProtocolHandler=" + oProtocolHandler.getClass()); // Check if user already has a tgt so that he/she doesn't need to be authenticated again if (_configManager.isSingleSignOn() && htServiceRequest.containsKey("aselect_credentials_tgt") && htServiceRequest.containsKey("aselect_credentials_uid") && htServiceRequest.containsKey("aselect_credentials_server_id")) { String sTgt = (String) htServiceRequest.get("aselect_credentials_tgt"); String sUid = (String) htServiceRequest.get("aselect_credentials_uid"); String sServerId = (String) htServiceRequest.get("aselect_credentials_server_id"); // check if a request was done for another user-id String sForcedUid = (String) _htSessionContext.get("forced_uid"); _systemLogger.log(Level.INFO, _sModule, sMethod, "DLOGIN sTgt=" + sTgt + " sUid=" + sUid + " sServerId=" + sServerId + " sForcedUid=" + sForcedUid); if (sForcedUid != null && !sUid.equals(sForcedUid)) { // user_id does not match _tgtManager.remove(sTgt); } else { // Reads the TGT into class variable _htTGTContext: int rc = checkCredentials(sTgt, sUid, sServerId); // valid credentials/level/SSO group if (rc >= 0) { // ok Boolean forcedAuthenticate = (Boolean) _htSessionContext.get("forced_authenticate"); if (forcedAuthenticate == null) forcedAuthenticate = false; _systemLogger.log(Level.INFO, _sModule, sMethod, "CheckCred OK forced=" + forcedAuthenticate); if (!forcedAuthenticate.booleanValue()) { // Valid tgt, no forced_authenticate, update TGT with app_id or local_organization // needed for attribute gathering in verify_tgt // No redirectSyncNeeded() mechanism here boolean mustChooseOrg = false; HashMap<String, String> hUserOrganizations = null; if (rc == 1) { // no organization choice was made // 20100318, Bauke: Organization selection is here AttributeGatherer ag = AttributeGatherer.getHandle(); hUserOrganizations = ag.gatherOrganizations(_htTGTContext); // Also places org_id in the TGT context: mustChooseOrg = Utils.handleOrganizationChoice(_htTGTContext, hUserOrganizations); } _systemLogger.log(Level.INFO, MODULE, sMethod, "MustChoose=" + mustChooseOrg + " UserOrgs=" + hUserOrganizations); Utils.copyHashmapValue("app_id", _htTGTContext, _htSessionContext); Utils.copyHashmapValue("local_organization", _htTGTContext, _htSessionContext); Utils.copyHashmapValue("language", _htTGTContext, _htSessionContext); _htTGTContext.put("rid", sRid); // RH, 20140925, sn /////////////////////////////////////////////////////////////////////////////////////////////////////////// Utils.copyHashmapValue("local_organization", _htTGTContext, _htSessionContext); // Copy sp_rid as well: xsaml20 Utils.copyHashmapValue("sp_rid", _htTGTContext, _htSessionContext); // 20110526, Bauke, copy sp_reqbinding too, it must survive SSO Utils.copyHashmapValue("sp_reqbinding", _htTGTContext, _htSessionContext); Utils.copyHashmapValue("RelayState", _htTGTContext, _htSessionContext); // Add the SP to SSO administration - xsaml20 String sAppId = (String) _htSessionContext.get("app_id"); String sTgtAppId = (String) _htTGTContext.get("app_id"); String spIssuer = (String) _htSessionContext.get("sp_issuer"); // Utils.copyHashmapValue("app_id", htTGTContext, _htSessionContext); if (sAppId != null) { if (spIssuer == null || sTgtAppId == null) _htTGTContext.put("app_id", sAppId); } if (spIssuer != null) { // saml20 sessions _htTGTContext.put("sp_issuer", spIssuer); // save latest issuer UserSsoSession ssoSession = (UserSsoSession) _htTGTContext.get("sso_session"); if (ssoSession == null) { _systemLogger.log(Level.INFO, MODULE, sMethod, "NEW SSO session for " + sUid + " issuer=" + spIssuer); ssoSession = new UserSsoSession(sUid, ""); // sTgt); } ServiceProvider sp = new ServiceProvider(spIssuer); ssoSession.addServiceProvider(sp); _systemLogger.log(Level.INFO, _sModule, sMethod, "UPD SSO session " + ssoSession); _htTGTContext.put("sso_session", ssoSession); } // Overwrite with the latest value of sp_assert_url, // so the customer can reach his home-SP again. Utils.copyHashmapValue("sp_assert_url", _htTGTContext, _htSessionContext); ///////////////////////////////////////////////////////////////////////////////////// // RH, 20140925, en _tgtManager.updateTGT(sTgt, _htTGTContext); // 20100210, Bauke: Present the Organization selection to the user // Leaves the Rid session in place, needed for the application url if (rc == 1 && mustChooseOrg) { Tools.pauseSensorData(_configManager, _systemLogger, _htSessionContext); //_sessionManager.update(sRid, _htSessionContext); // Write session // pauseSensorDate() already does this: _sessionManager.setUpdateSession(_htSessionContext, _systemLogger); // 20120401, Bauke: changed, was update() // The user must choose his organization String sSelectForm = org.aselect.server.utils.Utils.presentOrganizationChoice( _servletRequest, _configManager, _htSessionContext, sRid, (String) _htTGTContext.get("language"), hUserOrganizations); pwOut.println(sSelectForm); return; } // Redirect to application as user has already a valid tgt // RH, 20140925, so // String sRedirectUrl; // if (_htSessionContext.get("remote_session") == null) { // sRedirectUrl = (String)_htSessionContext.get("app_url"); // } // else { // sRedirectUrl = (String)_htSessionContext.get("local_as_url"); // } // RH, 20140925, eo String sRedirectUrl = extractRedirectURL(_htSessionContext); // RH, 20140925, n _systemLogger.log(Level.INFO, _sModule, sMethod, "REDIR " + sRedirectUrl); // 20111101, Bauke: added Sensor Tools.calculateAndReportSensorData(_configManager, _systemLogger, "srv_sbh", sRid, _htSessionContext, sTgt, true); // Session must be removed _sessionManager.setDeleteSession(_htSessionContext, _systemLogger); // 20120401, Bauke: postpone session action String sLang = (String) _htTGTContext.get("language"); TGTIssuer oTGTIssuer = new TGTIssuer(_sMyServerId); oTGTIssuer.sendTgtRedirect(sRedirectUrl, sTgt, sRid, _servletResponse, sLang); return; } // else: forcedAuthenticate: fall through } ////////////////////////////////////////////// handle forced_passive //////////////////////////////////// Boolean forced_passive = (Boolean) _htSessionContext.get("forced_passive"); _systemLogger.log(Level.INFO, _sModule, sMethod, "forced_passive=" + forced_passive); if (forced_passive != null && forced_passive.booleanValue()) { TGTIssuer oTGTIssuer = new TGTIssuer(_sMyServerId); String sLang = (String) _htSessionContext.get("language");// maybe no tgt context String sRedirectUrl = extractRedirectURL(_htSessionContext); oTGTIssuer.sendTgtRedirect(sRedirectUrl, null, sRid, _servletResponse, sLang); // redirect without tgt return; // Quit } ////////////////////////////////////////////////////////////////////////////////////////////// // TGT found but not sufficient. It could be partially sufficient though // (see the "next_authsp" mechanism). /* * We know the authsp here, and it's level, we can examine the TGT and see what level we already have. * if TGT-level >= authsp_level then we can skip a first_authsp and go to the next_authsp, etc */ String sAppId = (String) _htSessionContext.get("app_id"); Application aApp = _applicationManager.getApplication(sAppId); String first_authsp = aApp.getFirstAuthsp(); String next_authsp = _authspHandlerManager.getNextAuthSP(sAuthSPId, sAppId); int iAuthspLevel = _authspHandlerManager.getLevel(sAuthSPId); int iTgtLevel = getLevelFromTGT(_htTGTContext); _systemLogger.log(Level.INFO, _sModule, sMethod, "NEXT_AUTHSP app_id=" + sAppId + " authspLevel=" + iAuthspLevel + " tgtLevel=" + iTgtLevel + " first_authsp=" + first_authsp + " next_authsp=" + next_authsp); if (first_authsp != null && next_authsp != null && iTgtLevel >= iAuthspLevel) { // Skip to next_authsp // NOTE: sms is not a direct_authsp, therefore this does not work: // _htSessionContext.put("direct_authsp", next_authsp); // handleDirectLogin(htServiceRequest, servletResponse, pwOut); _htSessionContext.remove("direct_authsp"); // No other direct_authsp's yet _htSessionContext.put("forced_authsp", next_authsp); // RH, 20140424, sn Integer iSubLevel = null; try { iSubLevel = _applicationManager.getSubLevel(sAppId); _htSessionContext.put("sub_level", iSubLevel); // need not be saved } catch (ASelectException ae) { _systemLogger.log(Level.FINER, _sModule, sMethod, "No min_level found for application: " + sAppId); } // RH, 20140424, en getUserAuthsps(sRid, sUid); // can change the session too _sessionManager.setUpdateSession(_htSessionContext, _systemLogger); // 20120401, Bauke: changed, was update() String sNextauthspForm = _configManager.getHTMLForm("nextauthsp", _sUserLanguage, _sUserCountry); sNextauthspForm = Utils.replaceString(sNextauthspForm, "[rid]", sRid); sNextauthspForm = Utils.replaceString(sNextauthspForm, "[a-select-server]", (String) htServiceRequest.get("a-select-server")); sNextauthspForm = Utils.replaceString(sNextauthspForm, "[user_id]", sUid); sNextauthspForm = Utils.replaceString(sNextauthspForm, "[authsp]", next_authsp); sNextauthspForm = Utils.replaceString(sNextauthspForm, "[aselect_url]", (String) htServiceRequest.get("my_url")); sNextauthspForm = Utils.replaceString(sNextauthspForm, "[request]", "login3"); String sLanguage = (String) htServiceRequest.get("language"); // 20101027 _ String sCountry = (String) htServiceRequest.get("country"); // 20101027 _ sNextauthspForm = Utils.replaceString(sNextauthspForm, "[language]", sLanguage); sNextauthspForm = Utils.replaceString(sNextauthspForm, "[country]", sCountry); sNextauthspForm = _configManager.updateTemplate(sNextauthspForm, _htSessionContext, _servletRequest); _htSessionContext.put("user_state", "state_nextauthsp"); _sessionManager.setUpdateSession(_htSessionContext, _systemLogger); Tools.pauseSensorData(_configManager, _systemLogger, _htSessionContext); //20111102 //_sessionManager.update(sRid, _htSessionContext); // Write session pwOut.println(sNextauthspForm); return; } // If TGT was issued in cross mode, the user now has to // authenticate with a higher level in cross mode again String sTempOrg = (String) _htTGTContext.get("proxy_organization"); if (sTempOrg == null) sTempOrg = (String) _htTGTContext.get("organization"); if (!sTempOrg.equals(_sMyOrg)) { _htSessionContext.put("forced_uid", sUid); _htSessionContext.put("forced_organization", sTempOrg); _sessionManager.setUpdateSession(_htSessionContext, _systemLogger); // 20120401, Bauke: added _htSessionContext.put("user_state", "state_crosslogin"); Tools.pauseSensorData(_configManager, _systemLogger, _htSessionContext); //20111102 handleCrossLogin(htServiceRequest, _servletResponse, pwOut); return; } if ("direct_login2".equals(sRequest)) { if (!isUserAselectEnabled(sUid, hmUserIdent)) { // Check the UDB using the "AselectAccountEnabled" field htServiceRequest.put("password", ""); // Force error message in handleDirectLoginRequest() } } // User was originally authenticated at this A-Select Server // The userid is already known from the TGT htServiceRequest.put("user_id", sUid); // showDirectLoginForm(htServiceRequest,pwOut); _htSessionContext.put("user_state", "state_directlogin"); Tools.pauseSensorData(_configManager, _systemLogger, _htSessionContext); //20111102 oProtocolHandler.handleDirectLoginRequest(htServiceRequest, _servletRequest, _servletResponse, _htSessionContext, hmUserIdent, pwOut, _sMyServerId, _sUserLanguage, _sUserCountry); _systemLogger.log(Level.FINE, _sModule, sMethod, "DirectLoginRequest handled (TGT)"); return; } } _systemLogger.log(Level.INFO, _sModule, sMethod, "No TGT, Continue"); // no TGT found or killed (other uid) ////////////////////////////////////////////// handle forced_passive //////////////////////////////////// Boolean forced_passive = (Boolean) _htSessionContext.get("forced_passive"); _systemLogger.log(Level.INFO, _sModule, sMethod, "forced_passive=" + forced_passive); if (forced_passive != null && forced_passive.booleanValue()) { TGTIssuer oTGTIssuer = new TGTIssuer(_sMyServerId); String sLang = (String) _htSessionContext.get("language");// maybe no tgt context String sRedirectUrl = extractRedirectURL(_htSessionContext); oTGTIssuer.sendTgtRedirect(sRedirectUrl, null, sRid, _servletResponse, sLang); // redirect without tgt return; // Quit } ////////////////////////////////////////////////////////////////////////////////////////////// if (!_configManager.isUDBEnabled() || _htSessionContext.containsKey("forced_organization")) { handleCrossLogin(htServiceRequest, _servletResponse, pwOut); return; } String sForcedUid = (String) _htSessionContext.get("forced_uid"); if (sForcedUid != null) { htServiceRequest.put("user_id", sForcedUid); // showDirectLoginForm(htServiceRequest,pwOut); } if ("direct_login2".equals(sRequest)) { String sUid = (String) htServiceRequest.get("user_id"); if (!isUserAselectEnabled(sUid, hmUserIdent)) { // Check the UDB using the "AselectAccountEnabled" field htServiceRequest.put("password", ""); // Force error message in handleDirectLoginRequest() } } // Will issue a TGT if everything is ok _htSessionContext.put("user_state", "state_directlogin"); Tools.pauseSensorData(_configManager, _systemLogger, _htSessionContext); //20111102 oProtocolHandler.handleDirectLoginRequest(htServiceRequest, _servletRequest, _servletResponse, _htSessionContext, hmUserIdent, pwOut, _sMyServerId, _sUserLanguage, _sUserCountry); _systemLogger.log(Level.FINE, _sModule, sMethod, "DirectLoginRequest handled (no TGT)"); } catch (ASelectException e) { throw e; } catch (Exception e) { _systemLogger.log(Level.WARNING, _sModule, sMethod, "Internal error: ", e); throw new ASelectException(Errors.ERROR_ASELECT_INTERNAL_ERROR, e); } }
From source file:foodsimulationmodel.pathmapping.Route.java
/** * Find the buildings which can be accessed from the given road (the given road is the closest to the buildings). * Uses a separate cache object which can be serialised so that the cache doesn't need to be rebuilt every time. * //w w w.j a v a2 s .c om * @param road * @return * @throws Exception */ private List<IAgent> getBuildingsOnRoad(Road road) throws Exception { if (buildingsOnRoadCache == null) { LOGGER.log(Level.FINER, "Route.getBuildingsOnRoad called for first time, " + "creating cache of all roads and the buildings which are on them ..."); // Create a new cache object, this will be read from disk if possible (which is why the // getInstance() method is used instead of the constructor. String gisDir = GlobalVars.GISDataDirectory; File buildingsFile = new File(gisDir + GlobalVars.BuildingShapefile); File roadsFile = new File(gisDir + GlobalVars.RoadShapefile); File serialLoc = new File(gisDir + ContextManager.getProperty(GlobalVars.BuildingsRoadsCache)); buildingsOnRoadCache = BuildingsOnRoadCache.getInstance(ContextManager.agentGeography, buildingsFile, ContextManager.roadProjection, roadsFile, serialLoc, new GeometryFactory()); } // if not cached return buildingsOnRoadCache.get(road); }
From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.dta.DTAFileReader.java
private void decodeData(BufferedInputStream stream) throws IOException { dbgLog.fine("\n***** decodeData(): start *****"); if (stream == null) { throw new IllegalArgumentException("stream == null!"); }/*w ww.java 2 s.c o m*/ //int nvar = (Integer)smd.getFileInformation().get("varQnty"); int nvar = dataTable.getVarQuantity().intValue(); //int nobs = (Integer)smd.getFileInformation().get("caseQnty"); int nobs = dataTable.getCaseQuantity().intValue(); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("data dimensions[observations x variables] = (" + nobs + "x" + nvar + ")"); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("bytes per row=" + bytes_per_row + " bytes"); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("variableTypes=" + Arrays.deepToString(variableTypes)); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("StringLengthTable=" + StringLengthTable); } // create a File object to save the tab-delimited data file FileOutputStream fileOutTab = null; PrintWriter pwout = null; File tabDelimitedDataFile = File.createTempFile("tempTabfile.", ".tab"); // save the temp tab-delimited file in the return ingest object: ingesteddata.setTabDelimitedFile(tabDelimitedDataFile); fileOutTab = new FileOutputStream(tabDelimitedDataFile); pwout = new PrintWriter(new OutputStreamWriter(fileOutTab, "utf8"), true); /* Should we lose this dateFormat thing in 4.0? * the UNF should be calculatable on the app side solely from the data * stored in the tab file and the type information stored the dataVariable * object. * furthermore, the very idea of storing a format entry not just for * every variable, but for every value/observation is a bit strange. * TODO: review and confirm that, in the 3.* implementation, every * entry in dateFormat[nvar][*] is indeed the same - except for the * missing value entries. -- L.A. 4.0 (OK, I got rid of the dateFormat; instead I kinda sorta assume that the format is the same for every value in a column, save for the missing values... like this: dataTable.getDataVariables().get(columnCounter).setFormatSchemaName(ddt.format); BUT, this needs to be reviewed/confirmed etc! */ //String[][] dateFormat = new String[nvar][nobs]; for (int i = 0; i < nobs; i++) { byte[] dataRowBytes = new byte[bytes_per_row]; Object[] dataRow = new Object[nvar]; int nbytes = stream.read(dataRowBytes, 0, bytes_per_row); if (nbytes == 0) { String errorMessage = "reading data: no data were read at(" + i + "th row)"; throw new IOException(errorMessage); } // decoding each row int byte_offset = 0; for (int columnCounter = 0; columnCounter < variableTypes.length; columnCounter++) { Integer varType = variableTypeMap.get(variableTypes[columnCounter]); // 4.0 Check if this is a time/date variable: boolean isDateTimeDatum = false; String formatCategory = dataTable.getDataVariables().get(columnCounter).getFormatCategory(); if (formatCategory != null && (formatCategory.equals("time") || formatCategory.equals("date"))) { isDateTimeDatum = true; } String variableFormat = dateVariableFormats[columnCounter]; switch (varType != null ? varType : 256) { case -5: // Byte case // note: 1 byte signed byte byte_datum = dataRowBytes[byte_offset]; if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column byte =" + byte_datum); } if (byte_datum >= BYTE_MISSING_VALUE) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column byte MV=" + byte_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { dataRow[columnCounter] = byte_datum; } byte_offset++; break; case -4: // Stata-int (=java's short: 2byte) case // note: 2-byte signed int, not java's int ByteBuffer int_buffer = ByteBuffer.wrap(dataRowBytes, byte_offset, 2); if (isLittleEndian) { int_buffer.order(ByteOrder.LITTLE_ENDIAN); } short short_datum = int_buffer.getShort(); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column stata int =" + short_datum); } if (short_datum >= INT_MISSIG_VALUE) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column stata long missing value=" + short_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { if (isDateTimeDatum) { DecodedDateTime ddt = decodeDateTimeData("short", variableFormat, Short.toString(short_datum)); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format=" + ddt.format); } dataRow[columnCounter] = ddt.decodedDateTime; //dateFormat[columnCounter][i] = ddt.format; dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format); } else { dataRow[columnCounter] = short_datum; } } byte_offset += 2; break; case -3: // stata-Long (= java's int: 4 byte) case // note: 4-byte singed, not java's long //dbgLog.fine("DATreader: stata long"); ByteBuffer long_buffer = ByteBuffer.wrap(dataRowBytes, byte_offset, 4); if (isLittleEndian) { long_buffer.order(ByteOrder.LITTLE_ENDIAN); } int int_datum = long_buffer.getInt(); if (dbgLog.isLoggable(Level.FINE)) { //dbgLog.fine(i + "-th row " + columnCounter // + "=th column stata long =" + int_datum); } if (int_datum >= LONG_MISSING_VALUE) { if (dbgLog.isLoggable(Level.FINE)) { //dbgLog.fine(i + "-th row " + columnCounter // + "=th column stata long missing value=" + int_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { if (isDateTimeDatum) { DecodedDateTime ddt = decodeDateTimeData("int", variableFormat, Integer.toString(int_datum)); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format=" + ddt.format); } dataRow[columnCounter] = ddt.decodedDateTime; dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format); } else { dataRow[columnCounter] = int_datum; } } byte_offset += 4; break; case -2: // float case // note: 4-byte ByteBuffer float_buffer = ByteBuffer.wrap(dataRowBytes, byte_offset, 4); if (isLittleEndian) { float_buffer.order(ByteOrder.LITTLE_ENDIAN); } float float_datum = float_buffer.getFloat(); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column float =" + float_datum); } if (FLOAT_MISSING_VALUE_SET.contains(float_datum)) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column float missing value=" + float_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { if (isDateTimeDatum) { DecodedDateTime ddt = decodeDateTimeData("float", variableFormat, doubleNumberFormatter.format(float_datum)); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format=" + ddt.format); } dataRow[columnCounter] = ddt.decodedDateTime; dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format); } else { dataRow[columnCounter] = float_datum; // This may be temporary - but for now (as in, while I'm testing // 4.0 ingest against 3.* ingest, I need to be able to tell if a // floating point value was a single, or double float in the // original STATA file: -- L.A. Jul. 2014 dataTable.getDataVariables().get(columnCounter).setFormat("float"); } } byte_offset += 4; break; case -1: // double case // note: 8-byte ByteBuffer double_buffer = ByteBuffer.wrap(dataRowBytes, byte_offset, 8); if (isLittleEndian) { double_buffer.order(ByteOrder.LITTLE_ENDIAN); } double double_datum = double_buffer.getDouble(); if (DOUBLE_MISSING_VALUE_SET.contains(double_datum)) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column double missing value=" + double_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { if (isDateTimeDatum) { DecodedDateTime ddt = decodeDateTimeData("double", variableFormat, doubleNumberFormatter.format(double_datum)); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format=" + ddt.format); } dataRow[columnCounter] = ddt.decodedDateTime; dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format); } else { dataRow[columnCounter] = doubleNumberFormatter.format(double_datum); } } byte_offset += 8; break; case 0: // String case int strVarLength = StringLengthTable.get(columnCounter); String raw_datum = new String( Arrays.copyOfRange(dataRowBytes, byte_offset, (byte_offset + strVarLength)), "ISO-8859-1"); // TODO: // is it the right thing to do, to default to "ISO-8859-1"? // (it may be; since there's no mechanism for specifying // alternative encodings in Stata, this may be their default; // it just needs to be verified. -- L.A. Jul. 2014) String string_datum = getNullStrippedString(raw_datum); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column string =" + string_datum); } if (string_datum.isEmpty()) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column string missing value=" + string_datum); } // TODO: /* Is this really a missing value case? * Or is it an honest empty string? * Is there such a thing as a missing value for a String in Stata? * -- L.A. 4.0 */ dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { /* * Some special characters, like new lines and tabs need to * be escaped - otherwise they will break our TAB file * structure! * But before we escape anything, all the back slashes * already in the string need to be escaped themselves. */ String escapedString = string_datum.replace("\\", "\\\\"); // escape quotes: escapedString = escapedString.replaceAll("\"", Matcher.quoteReplacement("\\\"")); // escape tabs and new lines: escapedString = escapedString.replaceAll("\t", Matcher.quoteReplacement("\\t")); escapedString = escapedString.replaceAll("\n", Matcher.quoteReplacement("\\n")); escapedString = escapedString.replaceAll("\r", Matcher.quoteReplacement("\\r")); // the escaped version of the string is stored in the tab file // enclosed in double-quotes; this is in order to be able // to differentiate between an empty string (tab-delimited empty string in // double quotes) and a missing value (tab-delimited empty string). // Although the question still remains - is it even possible // to store an empty string, that's not a missing value, in Stata? // - see the comment in the missing value case above. -- L.A. 4.0 dataRow[columnCounter] = "\"" + escapedString + "\""; } byte_offset += strVarLength; break; default: dbgLog.fine("unknown variable type found"); String errorMessage = "unknow variable Type found at data section"; throw new InvalidObjectException(errorMessage); } // switch } // for-columnCounter // Dump the row of data to the tab-delimited file we are producing: pwout.println(StringUtils.join(dataRow, "\t")); if (dbgLog.isLoggable(Level.FINE)) { //dbgLog.fine(i + "-th row's data={" + StringUtils.join(dataRow, ",") + "};"); } } // for- i (row) pwout.close(); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("variableTypes:\n" + Arrays.deepToString(variableTypes)); } dbgLog.fine("DTA Ingest: decodeData(): end."); }
From source file:org.cloudifysource.rest.controllers.DeploymentsController.java
/** * Retrieves application level attributes. * //from w w w. j a v a 2 s .co m * @param appName * The application name. * @return An instance of {@link GetApplicationAttributesResponse} containing all the application attributes names * and values. * @throws ResourceNotFoundException * Thrown in case the application does not exist. */ @RequestMapping(value = "/{appName}/attributes", method = RequestMethod.GET) public GetApplicationAttributesResponse getApplicationAttributes(@PathVariable final String appName) throws ResourceNotFoundException { // valid application if exist controllerHelper.getApplication(appName); if (logger.isLoggable(Level.FINER)) { logger.finer("received request to get all attributes of application " + appName); } // get attributes final Map<String, Object> attributes = controllerHelper.getAttributes(appName, null, null); // create response object final GetApplicationAttributesResponse aar = new GetApplicationAttributesResponse(); // set attributes aar.setAttributes(attributes); return aar; }
From source file:org.fornax.cartridges.sculptor.smartclient.server.ScServlet.java
private void sendResponse(PrintWriter output, PagedResult<?> pResult) throws IllegalArgumentException { List<?> inputData = pResult.getValues() == null ? new ArrayList<Object>() : pResult.getValues(); int showEndRow = pResult.getEndRow() < 1 ? 0 : pResult.getEndRow(); int totalRows; if (pResult.isTotalCounted()) { totalRows = pResult.getTotalRows(); } else if (pResult.isAddionalResultCounted()) { totalRows = pResult.getEndRow() + pResult.getAdditionalResultRows(); } else {/*from www. ja va 2 s. c o m*/ totalRows = pResult.getStartRow() + pResult.getValues().size() + 1; } log.log(Level.FINE, "Sending JSON response from {0} to {1} of size {2}", new Object[] { pResult.getStartRow(), showEndRow, inputData.size() }); output.write("{response: { status:0, startRow:" + pResult.getStartRow() + ", endRow:" + showEndRow + ", totalRows:" + totalRows + ", data:["); String delim = ""; for (Object obj : inputData) { output.write(delim); // Prepare string representation and write to out String objString = mapObjToOutput(obj, DEF_DEPTH, new Stack(), false, false); log.log(Level.FINER, " >>>>>>>>>>> {0}", objString); output.write(objString); delim = ", "; } output.write(" ] } }"); }
From source file:org.cloudifysource.rest.controllers.DeploymentsController.java
/** * Deletes an application level attribute. * //from w w w .j av a 2 s .c o m * @param appName * The application name. * @param attributeName * The attribute name. * @return The previous value of the attribute. * @throws ResourceNotFoundException * Thrown in case the application does not exist. * @throws RestErrorException * Thrown in case the attribute name is empty. */ @RequestMapping(value = "/{appName}/attributes/{attributeName}", method = RequestMethod.DELETE) public DeleteApplicationAttributeResponse deleteApplicationAttribute(@PathVariable final String appName, @PathVariable final String attributeName) throws ResourceNotFoundException, RestErrorException { // valid application if exist controllerHelper.getApplication(appName); if (logger.isLoggable(Level.FINER)) { logger.finer("received request to delete attributes " + attributeName + " of application " + appName); } // delete attribute returned previous value final Object previousValue = controllerHelper.deleteAttribute(appName, null, null, attributeName); final DeleteApplicationAttributeResponse daar = new DeleteApplicationAttributeResponse(); daar.setPreviousValue(previousValue); return daar; }
From source file:foodsimulationmodel.pathmapping.Route.java
private void populateCache(Geography<IAgent> buildingEnvironment, Geography<Road> roadEnvironment, GeometryFactory geomFac) throws Exception { double time = System.nanoTime(); for (IAgent b : buildingEnvironment.getAllObjects()) { // Find the closest road to this building Geometry buildingPoint = geomFac.createPoint(b.getCoords()); double minDistance = Double.MAX_VALUE; Road closestRoad = null;/*from w w w . j av a 2 s . c o m*/ double distance; Envelope e = buildingPoint.buffer(GlobalVars.GEOGRAPHY_PARAMS.BUFFER_DISTANCE.LARGE.dist) .getEnvelopeInternal(); for (Road r : roadEnvironment.getObjectsWithin(e)) { distance = DistanceOp.distance(buildingPoint, ContextManager.roadProjection.getGeometry(r)); if (distance < minDistance) { minDistance = distance; closestRoad = r; } } // for roads // Found the closest road, add the information to the cache if (theCache.containsKey(closestRoad)) { theCache.get(closestRoad).add(b); this.referenceCache.get(closestRoad.getIdentifier()).add(b.getIdentifier()); } else { ArrayList<IAgent> l = new ArrayList<IAgent>(); l.add(b); theCache.put(closestRoad, l); ArrayList<String> l2 = new ArrayList<String>(); l2.add(b.getIdentifier()); this.referenceCache.put(closestRoad.getIdentifier(), l2); } } // for buildings int numRoads = theCache.keySet().size(); int numBuildings = 0; for (List<IAgent> l : theCache.values()) numBuildings += l.size(); LOGGER.log(Level.FINER, "Finished caching roads and buildings. Cached " + numRoads + " roads and " + numBuildings + " buildings in " + 0.000001 * (System.nanoTime() - time) + "ms"); }
From source file:foodsimulationmodel.pathmapping.Route.java
private void serialise() throws IOException { double time = System.nanoTime(); FileOutputStream fos = null;/*www.j a v a 2 s.com*/ ObjectOutputStream out = null; try { if (!this.serialisedLoc.exists()) this.serialisedLoc.createNewFile(); fos = new FileOutputStream(this.serialisedLoc); out = new ObjectOutputStream(fos); out.writeObject(this); out.close(); } catch (IOException ex) { if (serialisedLoc.exists()) serialisedLoc.delete(); // delete to stop problems loading incomplete file next time throw ex; } LOGGER.log(Level.FINER, "Serialised BuildingsOnRoadCache to " + this.serialisedLoc.getAbsolutePath() + " in (" + 0.000001 * (System.nanoTime() - time) + "ms)"); }