List of usage examples for java.text MessageFormat format
public static String format(String pattern, Object... arguments)
From source file:com.asakusafw.runtime.util.lock.LocalFileLockProvider.java
@Override public LocalFileLockObject<T> tryLock(T target) throws IOException { if (baseDirectory.mkdirs() == false && baseDirectory.isDirectory() == false) { throw new IOException(MessageFormat.format("Failed to create lock directory: {0}", baseDirectory)); }/*www .j a v a2 s .c om*/ String fileName = String.format("%08x.lck", target == null ? -1 : target.hashCode()); //$NON-NLS-1$ File lockFile = new File(baseDirectory, fileName); RandomAccessFile fd = new RandomAccessFile(lockFile, "rw"); //$NON-NLS-1$ boolean success = false; try { if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Start to acquire lock for \"{0}\" ({1})", //$NON-NLS-1$ target, lockFile)); } FileLock lockEntity = getLock(target, lockFile, fd); if (lockEntity == null) { return null; } else { if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Finished to acquire lock for \"{0}\" ({1})", //$NON-NLS-1$ target, lockFile)); } try { fd.seek(0L); fd.setLength(0L); fd.write(String.valueOf(target).getBytes(ENCODING)); success = true; return new LocalFileLockObject<>(target, lockFile, fd, lockEntity); } finally { if (success == false) { lockEntity.release(); } } } } finally { if (success == false) { fd.close(); } } }
From source file:com.gitblit.utils.CompressionUtils.java
/** * Log an error message and exception.//w w w. ja v a2 s . com * * @param t * @param repository * if repository is not null it MUST be the {0} parameter in the * pattern. * @param pattern * @param objects */ private static void error(Throwable t, Repository repository, String pattern, Object... objects) { List<Object> parameters = new ArrayList<Object>(); if (objects != null && objects.length > 0) { for (Object o : objects) { parameters.add(o); } } if (repository != null) { parameters.add(0, repository.getDirectory().getAbsolutePath()); } LOGGER.error(MessageFormat.format(pattern, parameters.toArray()), t); }
From source file:com.eu.evaluation.server.service.impl.importdata.DefaultImportDataActuator.java
public <T extends ListResponse<V>, V extends IPositionEntity> void importData(AccessSystem accessSystem, ImportDataConfig config) throws ClassNotFoundException { EntityEnum entityEnum = EntityEnum.getByInstanceType(config.getInstanceType()); if (entityEnum != null) { String message = "{0} {1} ? {2}"; logger.info(MessageFormat.format(message, new Object[] { "", accessSystem.getName(), entityEnum.getName() })); URI uri = getUrl(accessSystem, config); Class<T> listClass = (Class<T>) config.getListResponse(); try {/*from w w w . ja v a 2 s . co m*/ T list = (T) restTemplate.getForObject(uri, listClass); if (list.getRows() != null) { int deleteCount = defaultDAO.deleteData(config.getOrgInstanceClass(), accessSystem.getCode()); String deleteMessage = " {0} {1} ? {2} ?"; logger.debug(MessageFormat.format(deleteMessage, new Object[] { accessSystem.getName(), entityEnum.getName(), deleteCount })); for (V v : list.getRows()) { v.setPosition(accessSystem.getCode()); } defaultDAO.save(list.getRows()); String saveMessage = " {0} {1} {2} ?"; logger.debug(MessageFormat.format(saveMessage, new Object[] { accessSystem.getName(), entityEnum.getName(), list.getRows().size() })); } logger.info(MessageFormat.format(message, new Object[] { "?", accessSystem.getName(), entityEnum.getName() })); } catch (RestClientException e) { message = " {0} ? {1} ??RestClientException"; logger.error(MessageFormat.format(message, new Object[] { accessSystem.getName(), entityEnum.getName() }), e); } } else { String message = " {0} ? {1} ? {1} "; logger.info( MessageFormat.format(message, new Object[] { accessSystem.getName(), entityEnum.getName() })); } }
From source file:at.alladin.rmbt.controlServer.IpResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();/*from w w w. j av a 2 s. c o m*/ JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); String answerString; final String clientIpRaw = getIP(); final InetAddress clientAddress = InetAddresses.forString(clientIpRaw); System.out.println(MessageFormat.format(labels.getString("NEW_IP_REQ"), clientIpRaw)); if (entity != null && !entity.isEmpty()) { // try parse the string to a JSON object try { // debug parameters sent request = new JSONObject(entity); System.out.println(request.toString(4)); /* sample request data { "api_level": "21", "device": "hammerhead", "language": "en", "model": "Nexus 5", "os_version": "5.0(1570415)", "plattform": "Android", "product": "hammerhead", "softwareRevision": "master_initial-2413-gf89049d", "softwareVersionCode": 20046, "softwareVersionName": "2.0.46", "timezone": "Europe/Vienna", "type": "MOBILE", "uuid": "........(uuid)........" "location": { "accuracy": 20, "age": 7740, "lat": 51.1053539, "long": 17.4921002, "provider": "network" }, } */ UUID uuid = null; final String uuidString = request.optString("uuid", ""); if (uuidString.length() != 0) uuid = UUID.fromString(uuidString); final String clientPlattform = request.getString("plattform"); final String clientModel = request.getString("model"); final String clientProduct = request.getString("product"); final String clientDevice = request.getString("device"); final String clientSoftwareVersionCode = request.getString("softwareVersionCode"); final String clientApiLevel = request.getString("api_level"); final JSONObject location = request.optJSONObject("location"); long geoage = 0; // age in ms double geolat = 0; double geolong = 0; float geoaccuracy = 0; // in m double geoaltitude = 0; float geospeed = 0; // in m/s String geoprovider = ""; if (!request.isNull("location")) { geoage = location.optLong("age", 0); geolat = location.optDouble("lat", 0); geolong = location.optDouble("long", 0); geoaccuracy = (float) location.optDouble("accuracy", 0); geoaltitude = location.optDouble("altitude", 0); geospeed = (float) location.optDouble("speed", 0); geoprovider = location.optString("provider", ""); } if (errorList.getLength() == 0) try { PreparedStatement st; st = conn.prepareStatement( "INSERT INTO status(client_uuid,time,plattform,model,product,device,software_version_code,api_level,ip," + "age,lat,long,accuracy,altitude,speed,provider)" + "VALUES(?, NOW(),?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); int i = 1; st.setObject(i++, uuid); st.setObject(i++, clientPlattform); st.setObject(i++, clientModel); st.setObject(i++, clientProduct); st.setObject(i++, clientDevice); st.setObject(i++, clientSoftwareVersionCode); st.setObject(i++, clientApiLevel); st.setObject(i++, clientIpRaw); // location information st.setObject(i++, geoage); st.setObject(i++, geolat); st.setObject(i++, geolong); st.setObject(i++, geoaccuracy); st.setObject(i++, geoaltitude); st.setObject(i++, geospeed); st.setObject(i++, geoprovider); final int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_STORE_STATUS"); } catch (final SQLException e) { errorList.addError("ERROR_DB_STORE_GENERAL"); e.printStackTrace(); } answer.put("ip", clientIpRaw); if (clientAddress instanceof Inet4Address) { answer.put("v", "4"); } else if (clientAddress instanceof Inet6Address) { answer.put("v", "6"); } else { answer.put("v", "0"); } } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSON Data " + e.toString()); } } else { errorList.addErrorString("Expected request is missing."); } try { answer.putOpt("error", errorList.getList()); } catch (final JSONException e) { System.out.println("Error saving ErrorList: " + e.toString()); } answerString = answer.toString(); return answerString; }
From source file:com.asakusafw.runtime.flow.join.JoinResource.java
@Override public void setup(JobContext context) throws IOException, InterruptedException { if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Building join-table from \"{0}\" on distributed cache", //$NON-NLS-1$ getCacheName()));//from ww w .jav a 2 s . co m } try (StageResourceDriver driver = new StageResourceDriver(context)) { List<Path> paths = driver.findCache(getCacheName()); if (paths.isEmpty()) { throw new FileNotFoundException( MessageFormat.format("Missing resource \"{0}\" in distributed cache", getCacheName())); } if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Building join table \"{0}\" using \"{1}\"", //$NON-NLS-1$ getCacheName(), paths)); } try { table = createTable(driver, paths); } catch (IOException e) { throw new IOException( MessageFormat.format("Failed to build a join table from \"{0}\"", getCacheName()), e); } if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Built join-table from \"{0}\"", //$NON-NLS-1$ getCacheName())); } } }
From source file:com.microsoft.tfs.core.ws.runtime.client.BufferedSOAPRequestEntity.java
@Override public long getContentLength() { try {// ww w. j a v a 2 s. co m ensureRequestIsBuffered(); } catch (final IOException e) { final String messageFormat = "Content length not available because buffering of request body failed: {0}"; //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, e.getMessage()); throw new RuntimeException(message); } return buffer.size(); }
From source file:com.github.aynu.mosir.core.standard.util.PropertiesHelper.java
/** * ??//from ww w . j av a 2s . co m * @param key * @param arguments ? * @return */ public String getText(final String key, final Object... arguments) { final String text = config.getString(key); Validate.notNull(text); return MessageFormat.format(text, arguments); }
From source file:com.ibm.watson.apis.conversation_with_discovery.rest.SetupResource.java
/** * Method to fetch config JSON object and also the workspace_id. * * @return response//from ww w . j a v a 2s . co m */ @GET @Produces(MediaType.APPLICATION_JSON) public Response getConfig() { String workspaceId = System.getenv(Constants.WORKSPACE_ID); logger.debug(MessageFormat.format(Messages.getString("SetupResource.WORKSPACE_ID_IS"), workspaceId)); JsonObject config = new JsonObject(); config.addProperty(Constants.SETUP_STATUS_MESSAGE, Messages.getString("SetupResource.SETUP_STATUS_MSG")); config.addProperty(Constants.SETUP_STEP, "0"); config.addProperty(Constants.SETUP_STATE, Constants.NOT_READY); config.addProperty(Constants.SETUP_PHASE, Messages.getString("SetupResource.PHASE_ERROR")); config.addProperty(Constants.SETUP_MESSAGE, Messages.getString("SetupResource.CHECK_LOGS")); // Fetch the updated config JSON object from the servlet listener config = new AppServletContextListener().getJsonConfig(); config.addProperty(Constants.SETUP_STATUS_MESSAGE, Messages.getString("SetupResource.SETUP_STATUS_MSG")); logger.debug(Messages.getString("SetupResource.CONFIG_STATUS") + config); config.addProperty(Constants.WORKSPACE_ID, workspaceId); if (config.has(Constants.SETUP_STEP) && (config.get(Constants.SETUP_STEP).getAsInt() == 3) && config.get(Constants.SETUP_STATE).getAsString().equalsIgnoreCase(Constants.READY)) { if (StringUtils.isBlank(workspaceId)) { config.addProperty(Constants.SETUP_STEP, "0"); config.addProperty(Constants.SETUP_STATE, Constants.NOT_READY); config.addProperty(Constants.SETUP_PHASE, Messages.getString("SetupResource.PHASE_ERROR")); config.addProperty(Constants.SETUP_MESSAGE, Messages.getString("SetupResource.WORKSPACE_ID_ERROR")); } } return Response.ok(config.getAsJsonObject().toString().trim()).type(MediaType.APPLICATION_JSON) .header("Cache-Control", "no-cache").build(); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.engines.internal.OutputStreamDownloadOutput.java
/** * {@inheritDoc}//from ww w. j av a 2 s. co m */ @Override public synchronized void resetOutputStream() throws IOException { throw new IOException( MessageFormat.format("{0} does not support reset", OutputStreamDownloadOutput.class.getName())); //$NON-NLS-1$ }
From source file:edu.ucla.stat.SOCR.motionchart.MotionItemLabelGenerator.java
/** * Generates an item label for a particular item within a series. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series index (zero-based). * @param item the item index (zero-based). * @return The item label (possibly <code>null</code>). *//* ww w .j a va 2 s .co m*/ @Override public String generateLabel(XYDataset dataset, int series, int item) { if (dataset instanceof MotionDataSet) { return MessageFormat.format("{0}", ((MotionDataSet) dataset).getCategory(series, item)); } return super.generateLabel(dataset, series, item); }