Example usage for java.text MessageFormat format

List of usage examples for java.text MessageFormat format

Introduction

In this page you can find the example usage for java.text MessageFormat format.

Prototype

public final StringBuffer format(Object arguments, StringBuffer result, FieldPosition pos) 

Source Link

Document

Formats an array of objects and appends the MessageFormat's pattern, with format elements replaced by the formatted objects, to the provided StringBuffer.

Usage

From source file:com.microsoft.tfs.util.listeners.DefaultExceptionHandler.java

@Override
public boolean onException(final Object listener, final ListenerRunnable listenerRunnable,
        final ListenerList listenerList, final Throwable exception) {
    final String messageFormat = "listener [{0}] threw exception {1}"; //$NON-NLS-1$
    final String message = MessageFormat.format(messageFormat, listener, exception);
    log.warn(message, exception);//from   www  .  j  a  v a2 s. co  m
    return true;
}

From source file:org.duracloud.snapshottask.snapshot.RestartSnapshotTaskRunner.java

protected String buildBridgeURL(String snapshotId) {
    return MessageFormat.format("{0}/snapshot/{1}/restart", buildBridgeBaseURL(), snapshotId);
}

From source file:com.asakusafw.directio.hive.parquet.DecimalValueDriver.java

private static Method findBuilderMethod(String name) {
    try {/*w  w  w .  jav a 2 s .  com*/
        return PrimitiveBuilder.class.getMethod(name, int.class);
    } catch (ReflectiveOperationException e) {
        throw new IllegalStateException(MessageFormat.format("Parquet library does not support: {0}#{1}(int)",
                PrimitiveBuilder.class.getSimpleName(), name), e);
    }
}

From source file:com.microsoft.tfs.jni.internal.platformmisc.WindowsExecPlatformMisc.java

@Override
public String getEnvironmentVariable(final String name) {
    Check.notNullOrEmpty(name, "name"); //$NON-NLS-1$

    /*/*from   w  w  w. j  av  a 2 s  . c  om*/
     * Windows conventions surround variables with percent signs for shell
     * expansion.
     */
    final String variableName = "%" + name + "%"; //$NON-NLS-1$ //$NON-NLS-2$

    final String[] args = new String[] { "cmd", //$NON-NLS-1$
            "/c", //$NON-NLS-1$
            "echo", //$NON-NLS-1$
            variableName };

    final StringBuffer output = new StringBuffer();
    final int ret = ExecHelpers.exec(args, output);

    if (ret != 0) {
        log.error(MessageFormat.format("External command returned non-zero exit status {0}: {1}", //$NON-NLS-1$
                Integer.toString(ret), ExecHelpers.buildCommandForError(args)));
        return null;
    }

    final String value = output.toString().trim();

    /*
     * If the name we got is empty, or exactly matched the variable we tried
     * to expand, it was not set.
     */
    if (value.length() == 0 || value.equalsIgnoreCase(variableName)) {
        return null;
    }

    return value;
}

From source file:com.aperigeek.dropvault.dav.DropDAVClient.java

private void login() throws InvalidPasswordException, DAVException {
    String url = MessageFormat.format(LOGIN_URL, URLEncoder.encode(this.username), hash.hash(this.password));
    HttpGet get = new HttpGet(url);
    try {//from  w ww  .  j ava 2s  .  c om
        HttpResponse response = client.execute(get);

        if (response.getStatusLine().getStatusCode() == 401) {
            throw new InvalidPasswordException();
        }

        if (response.getStatusLine().getStatusCode() != 200) {
            throw new DAVException("Server error");
        }

        InputStream in = response.getEntity().getContent();
        StringWriter writer = new StringWriter();
        Reader reader = new InputStreamReader(in);
        char[] buffer = new char[128];
        int readed;
        while ((readed = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, readed);
        }
        in.close();
        baseUri = writer.toString().trim();
    } catch (IOException ex) {
        throw new DAVException("Login URL unavailable", ex);
    }
}

From source file:com.macrossx.wechat.impl.WechatHelper.java

/**
 * {@code _token_time}<tokentoken(7200-60)
 *//*from w w  w  .j av  a 2s. c  om*/
public Optional<WechatAccessToken> getAccessToken() {
    try {
        if (System.currentTimeMillis() < _token_time) {
            return Optional.of(_access_token);
        }
        long current = System.currentTimeMillis();
        HttpGet httpGet = new HttpGet();
        httpGet.setURI(new URI(MessageFormat.format(WechatConstants.ACCESS_TOKEN_URL, appid, appsecret)));
        return new WechatHttpClient().send(httpGet, WechatAccessToken.class).map((e) -> {
            _access_token = e;
            _token_time = current + _access_token.getExpires_in() - 60;
            return _access_token;
        });
    } catch (URISyntaxException e) {
        log.info(e.getMessage());
        return Optional.empty();
    }

}

From source file:au.id.hazelwood.xmltvguidebuilder.model.EpisodeDetail.java

public String getTitle() {
    StringBuilder builder = new StringBuilder();
    if (isNotBlank(seasonNumber) && isNotBlank(episodeNumber)) {
        if (isNumeric(seasonNumber) && isNumeric(episodeNumber)) {
            builder.append(MessageFormat.format("S{0}, E{1}. ", seasonNumber, episodeNumber));
        } else {//from  w  ww  .  j  ava2s  . c o m
            builder.append(MessageFormat.format("{0}, {1}. ", seasonNumber, episodeNumber));
        }
    }
    if (isNotBlank(title)) {
        builder.append(title);
    }
    return builder.toString();
}

From source file:com.bah.lucene.BlockCacheDirectoryFactoryV2.java

public BlockCacheDirectoryFactoryV2(Configuration configuration, long totalNumberOfBytes) {

    final int fileBufferSizeInt = configuration.getInt(BLUR_SHARD_BLOCK_CACHE_V2_FILE_BUFFER_SIZE, 8192);
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_FILE_BUFFER_SIZE, fileBufferSizeInt));
    final int cacheBlockSizeInt = configuration.getInt(BLUR_SHARD_BLOCK_CACHE_V2_CACHE_BLOCK_SIZE, 8192);
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_CACHE_BLOCK_SIZE, cacheBlockSizeInt));

    final Map<String, Integer> cacheBlockSizeMap = new HashMap<String, Integer>();
    for (Entry<String, String> prop : configuration) {
        String key = prop.getKey();
        if (key.startsWith(BLUR_SHARD_BLOCK_CACHE_V2_CACHE_BLOCK_SIZE_PREFIX)) {
            String value = prop.getValue();
            int cacheBlockSizeForFile = Integer.parseInt(value);
            String fieldType = key.substring(BLUR_SHARD_BLOCK_CACHE_V2_CACHE_BLOCK_SIZE_PREFIX.length());

            cacheBlockSizeMap.put(fieldType, cacheBlockSizeForFile);
            LOG.info(//  w  w w  .  jav  a 2s  .  c  o m
                    MessageFormat.format("{0}={1} for file type [{2}]", key, cacheBlockSizeForFile, fieldType));
        }
    }

    final STORE store = STORE.valueOf(configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_STORE, OFF_HEAP));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_STORE, store));

    final Set<String> cachingFileExtensionsForRead = getSet(
            configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_READ_CACHE_EXT, DEFAULT_VALUE));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_READ_CACHE_EXT,
            cachingFileExtensionsForRead));

    final Set<String> nonCachingFileExtensionsForRead = getSet(
            configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_READ_NOCACHE_EXT, DEFAULT_VALUE));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_READ_NOCACHE_EXT,
            nonCachingFileExtensionsForRead));

    final boolean defaultReadCaching = configuration.getBoolean(BLUR_SHARD_BLOCK_CACHE_V2_READ_DEFAULT, true);
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_READ_DEFAULT, defaultReadCaching));

    final Set<String> cachingFileExtensionsForWrite = getSet(
            configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_WRITE_CACHE_EXT, DEFAULT_VALUE));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_WRITE_CACHE_EXT,
            cachingFileExtensionsForWrite));

    final Set<String> nonCachingFileExtensionsForWrite = getSet(
            configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_WRITE_NOCACHE_EXT, DEFAULT_VALUE));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_WRITE_NOCACHE_EXT,
            nonCachingFileExtensionsForWrite));

    final boolean defaultWriteCaching = configuration.getBoolean(BLUR_SHARD_BLOCK_CACHE_V2_WRITE_DEFAULT, true);
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_WRITE_DEFAULT, defaultWriteCaching));

    Size fileBufferSize = new Size() {
        @Override
        public int getSize(CacheDirectory directory, String fileName) {
            return fileBufferSizeInt;
        }
    };

    Size cacheBlockSize = new Size() {
        @Override
        public int getSize(CacheDirectory directory, String fileName) {
            String ext = getExt(fileName);
            Integer size = cacheBlockSizeMap.get(ext);
            if (size != null) {
                return size;
            }
            return cacheBlockSizeInt;
        }
    };

    FileNameFilter readFilter = new FileNameFilter() {
        @Override
        public boolean accept(CacheDirectory directory, String fileName) {
            String ext = getExt(fileName);
            if (cachingFileExtensionsForRead.contains(ext)) {
                return true;
            } else if (nonCachingFileExtensionsForRead.contains(ext)) {
                return false;
            }
            return defaultReadCaching;
        }
    };

    FileNameFilter writeFilter = new FileNameFilter() {
        @Override
        public boolean accept(CacheDirectory directory, String fileName) {
            String ext = getExt(fileName);
            if (cachingFileExtensionsForWrite.contains(ext)) {
                return true;
            } else if (nonCachingFileExtensionsForWrite.contains(ext)) {
                return false;
            }
            return defaultWriteCaching;
        }
    };

    Quiet quiet = new Quiet() {
        @Override
        public boolean shouldBeQuiet(CacheDirectory directory, String fileName) {
            Thread thread = Thread.currentThread();
            String name = thread.getName();
            if (name.startsWith(SHARED_MERGE_SCHEDULER)) {
                return true;
            }
            return false;
        }
    };

    _cache = new BaseCache(totalNumberOfBytes, fileBufferSize, cacheBlockSize, readFilter, writeFilter, quiet,
            store);
}

From source file:com.collegesource.interfaces.student.BannerStudentFinder.java

/**
 * Find a student in Banner by name./*from   www .  j a  va  2  s .com*/
 * 
 * @param instidq
 * @param instid
 * @param firstName
 * @param lastName
 */
@Override
public List<StuMaster> findStudentByName(String instidq, String instid, String firstName, String lastName) {
    logger.debug(MessageFormat.format("Searching for student by firstName[{0}] and lastName[{1}]", firstName,
            lastName));
    List<Map<String, Object>> results = bannerDao.searchForStudentByName(firstName, lastName, logger);
    List<StuMaster> students = new ArrayList<StuMaster>();

    for (Map<String, Object> map : results) {
        students.add(createStudent(map));
    }

    return students;
}

From source file:ch.admin.suis.msghandler.servlet.CommandInterfaceConfiguration.java

/**
 * {@inheritDoc }//from   w  w w . j  a va 2 s  .com
 */
@Override
public String toString() {
    return MessageFormat.format("host name: {0}; port number: {1}",
            StringUtils.defaultIfEmpty(host, ClientCommons.NOT_SPECIFIED),
            port == 0 ? ClientCommons.NOT_SPECIFIED : port);
}