本文整理汇总了Java中java.util.Formatter类的典型用法代码示例。如果您正苦于以下问题:Java Formatter类的具体用法?Java Formatter怎么用?Java Formatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Formatter类属于java.util包,在下文中一共展示了Formatter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCertificateId
import java.util.Formatter; //导入依赖的package包/类
/**
* @return certificate id or -1 if not found
*/
public long getCertificateId(byte[] certificateBytes){
Formatter formatter = new Formatter();
for (byte b : Sha256Helper.sha256(certificateBytes)){
formatter.format("%02x", b);
}
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.query(TABLE_CERTIFICATES,
new String[]{COLUMN_ID},
COLUMN_FINGERPRINT + "=?", new String[]{formatter.toString()},
null, null, null);
long returnValue;
if (c.moveToFirst()){
returnValue = c.getLong(0);
} else {
returnValue = -1;
}
c.close();
db.close();
return returnValue;
}
示例2: openFile
import java.util.Formatter; //导入依赖的package包/类
public static void openFile()
{
try
{
output = new Formatter("clients.txt"); // open the file
}
catch (SecurityException securityException)
{
System.err.println("Write permission denied. Terminating.");
System.exit(1); // terminate the program
}
catch (FileNotFoundException fileNotFoundException)
{
System.err.println("Error opening file. Terminating.");
System.exit(1); // terminate the program
}
}
示例3: setHmacSeedReturnCode
import java.util.Formatter; //导入依赖的package包/类
@SimpleFunction(description = "Establish the secret seed for HOTP generation. " +
"Return the SHA1 of the provided seed, this will be used to contact the " +
"rendezvous server.")
public String setHmacSeedReturnCode(String seed) {
AppInvHTTPD.setHmacKey(seed);
MessageDigest Sha1;
try {
Sha1 = MessageDigest.getInstance("SHA1");
} catch (Exception e) {
Log.e(LOG_TAG, "Exception getting SHA1 Instance", e);
return "";
}
Sha1.update(seed.getBytes());
byte [] result = Sha1.digest();
StringBuffer sb = new StringBuffer(result.length * 2);
Formatter formatter = new Formatter(sb);
for (byte b : result) {
formatter.format("%02x", b);
}
Log.d(LOG_TAG, "Seed = " + seed);
Log.d(LOG_TAG, "Code = " + sb.toString());
return sb.toString();
}
示例4: toString
import java.util.Formatter; //导入依赖的package包/类
public String toString() {
StringBuilder sb = new StringBuilder(1024);
Formatter fm = new Formatter(sb);
if (creationTime() != null)
fm.format(" creationTime : %tc%n", creationTime().toMillis());
else
fm.format(" creationTime : null%n");
if (lastAccessTime() != null)
fm.format(" lastAccessTime : %tc%n", lastAccessTime().toMillis());
else
fm.format(" lastAccessTime : null%n");
fm.format(" lastModifiedTime: %tc%n", lastModifiedTime().toMillis());
fm.format(" isRegularFile : %b%n", isRegularFile());
fm.format(" isDirectory : %b%n", isDirectory());
fm.format(" isSymbolicLink : %b%n", isSymbolicLink());
fm.format(" isOther : %b%n", isOther());
fm.format(" fileKey : %s%n", fileKey());
fm.format(" size : %d%n", size());
fm.format(" compressedSize : %d%n", compressedSize());
fm.format(" crc : %x%n", crc());
fm.format(" method : %d%n", method());
fm.close();
return sb.toString();
}
示例5: addCertificate
import java.util.Formatter; //导入依赖的package包/类
private long addCertificate(byte[] certificateBytes){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_CERTIFICATE, certificateBytes);
Formatter formatter = new Formatter();
for (byte b : Sha256Helper.sha256(certificateBytes)){
formatter.format("%02x", b);
}
values.put(COLUMN_FINGERPRINT, formatter.toString());
long rowId = db.insert(TABLE_CERTIFICATES, null, values);
db.close();
return rowId;
}
示例6: collectEnvironmentInfo
import java.util.Formatter; //导入依赖的package包/类
/**
* Collect environment info with
* details on the java and os deployment
* versions.
*
* @return environment info
*/
private String collectEnvironmentInfo() {
final Properties properties = System.getProperties();
try (Formatter formatter = new Formatter()) {
formatter.format("\n******************** Welcome to CAS *******************\n");
formatter.format("CAS Version: %s\n", CasVersion.getVersion());
formatter.format("Build Date/Time: %s\n", CasVersion.getDateTime());
formatter.format("Java Home: %s\n", properties.get("java.home"));
formatter.format("Java Vendor: %s\n", properties.get("java.vendor"));
formatter.format("Java Version: %s\n", properties.get("java.version"));
formatter.format("OS Architecture: %s\n", properties.get("os.arch"));
formatter.format("OS Name: %s\n", properties.get("os.name"));
formatter.format("OS Version: %s\n", properties.get("os.version"));
formatter.format("*******************************************************\n");
return formatter.toString();
}
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:24,代码来源:CasEnvironmentContextListener.java
示例7: toString
import java.util.Formatter; //导入依赖的package包/类
@Override
public void toString(final StringBuilder builder) {
final String name = this.getName();
if (StringUtils.isNotBlank(name)) {
builder.append(name).append(':');
}
final int free = getPercentFree();
final Formatter formatter = new Formatter(builder);
if (useBytes) {
formatter.format("%.2f", heapSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE);
builder.append("MB heap, ");
formatter.format("%.2f", diskSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE);
builder.append("MB disk, ");
} else {
builder.append(heapSize).append(" items in heap, ");
builder.append(diskSize).append(" items on disk, ");
}
formatter.format("%.2f", offHeapSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE);
builder.append("MB off-heap, ");
builder.append(free).append("% free, ");
builder.append(getEvictions()).append(" evictions");
formatter.close();
}
示例8: stringForTime
import java.util.Formatter; //导入依赖的package包/类
public static String stringForTime(int timeMs) {
if (timeMs <= 0 || timeMs >= 24 * 60 * 60 * 1000) {
return "00:00";
}
int totalSeconds = timeMs / 1000;
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
StringBuilder stringBuilder = new StringBuilder();
Formatter mFormatter = new Formatter(stringBuilder, Locale.getDefault());
if (hours > 0) {
return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString();
} else {
return mFormatter.format("%02d:%02d", minutes, seconds).toString();
}
}
示例9: createTicketGrantingTicket
import java.util.Formatter; //导入依赖的package包/类
/**
* Create new ticket granting ticket.
*
* @param requestBody username and password application/x-www-form-urlencoded values
* @param request raw HttpServletRequest used to call this method
* @return ResponseEntity representing RESTful response
*/
@RequestMapping(value = "/tickets", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public final ResponseEntity<String> createTicketGrantingTicket(@RequestBody final MultiValueMap<String, String> requestBody,
final HttpServletRequest request) {
try (Formatter fmt = new Formatter()) {
final TicketGrantingTicket tgtId = this.cas.createTicketGrantingTicket(obtainCredential(requestBody));
final URI ticketReference = new URI(request.getRequestURL().toString() + '/' + tgtId.getId());
final HttpHeaders headers = new HttpHeaders();
headers.setLocation(ticketReference);
headers.setContentType(MediaType.TEXT_HTML);
fmt.format("<!DOCTYPE HTML PUBLIC \\\"-//IETF//DTD HTML 2.0//EN\\\"><html><head><title>");
//IETF//DTD HTML 2.0//EN\\\"><html><head><title>");
fmt.format("%s %s", HttpStatus.CREATED, HttpStatus.CREATED.getReasonPhrase())
.format("</title></head><body><h1>TGT Created</h1><form action=\"%s", ticketReference.toString())
.format("\" method=\"POST\">Service:<input type=\"text\" name=\"service\" value=\"\">")
.format("<br><input type=\"submit\" value=\"Submit\"></form></body></html>");
return new ResponseEntity<String>(fmt.toString(), headers, HttpStatus.CREATED);
} catch (final Throwable e) {
LOGGER.error(e.getMessage(), e);
return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
}
示例10: formatTo
import java.util.Formatter; //导入依赖的package包/类
@Override
public void formatTo(Formatter formatter, int flags, int width, int precision)
{
String s = null;
if ((flags & FormattableFlags.ALTERNATE) > 0)
{
s = toString();
}
else
{
s = "" + unicode;
}
formatTo(s, formatter, flags, width, precision);
}
示例11: outputHeader
import java.util.Formatter; //导入依赖的package包/类
/**
* Outputs stats headers into the 'output'.
*
* @param output
*/
public void outputHeader(Formatter output) {
if (output == null) return;
synchronized(output) {
output.format("MatchTime;UT2004Time;Health;Armor;Adrenaline;Score;Deaths;Suicides;Killed;WasKilled;NumKillsWithoutDeath;"
// 1 1.1 2 3 4 5 6 7 8 9 10
+"Team;TeamScore;"
// 11 12
+"ItemsCollect;WeaponsCollect;AmmoCollect;HealthCollect;ArmorCollect;ShieldCollect;AdrenalineCollect;OtherCollect;"
// 13 14 15 16 17 18 19 20
+"TimeMoving;TimeShooting;DoubleDamageCount;DoubleDamageTime;TraveledDistance;"
// 21 22 23 24 25
+"Combo;HasDoubleDamage;IsShooting;Velocity;Location_x;Location_y;Location_z");
// 26 27 28 29 30 31 32
// WEAPON USED
for (ItemType weapon : ItemType.Category.WEAPON.getTypes()) {
output.format(";" + fixSemicolon(weapon.getName()).replace(".", "_") + "_TimeUsed");
}
// EVENTS
output.format(";Event;EventParams...\n");
output.flush();
}
}
示例12: testApply
import java.util.Formatter; //导入依赖的package包/类
@Test
public void testApply() {
DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
Instant start = format.parseDateTime("2017-01-01 00:00:00").toInstant();
Instant end = format.parseDateTime("2017-01-01 00:01:00").toInstant();
IntervalWindow window = new IntervalWindow(start, end);
String projectId = "testProject_id";
String datasetId = "testDatasetId";
String tablePrefix = "testTablePrefix";
TableNameByWindowFn fn = new TableNameByWindowFn(projectId, datasetId, tablePrefix);
String result = fn.apply(window);
String expected = new Formatter()
.format("%s:%s.%s_%s", projectId, datasetId, tablePrefix, "20170101")
.toString();
assertEquals(expected, result);
}
示例13: toString
import java.util.Formatter; //导入依赖的package包/类
@Override
public void toString(final StringBuilder builder) {
final String name = this.getName();
if (StringUtils.isNotBlank(name)) {
builder.append(name).append(':');
}
final int free = getPercentFree();
try (Formatter formatter = new Formatter(builder)) {
if (this.useBytes) {
formatter.format("%.2f", this.heapSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE);
builder.append("MB heap, ");
formatter.format("%.2f", this.diskSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE);
builder.append("MB disk, ");
} else {
builder.append(this.heapSize).append(" items in heap, ");
builder.append(this.diskSize).append(" items on disk, ");
}
formatter.format("%.2f", this.offHeapSize / TOTAL_NUMBER_BYTES_IN_ONE_MEGABYTE);
builder.append("MB off-heap, ");
builder.append(free).append("% free, ");
builder.append(getEvictions()).append(" evictions");
}
}
示例14: toString
import java.util.Formatter; //导入依赖的package包/类
@Override
public String toString() {
// Output into coordinate format. Indices start from 1 instead of 0
Formatter out = new Formatter();
out.format("%10d %19d\n", size, Matrices.cardinality(this));
int i = 0;
for (VectorEntry e : this) {
if (e.get() != 0)
out.format("%10d % .12e\n", e.index() + 1, e.get());
if (++i == 100) {
out.format("...\n");
break;
}
}
return out.toString();
}
示例15: BytetohexString
import java.util.Formatter; //导入依赖的package包/类
static String BytetohexString(byte[] b, boolean reverse) {
StringBuilder sb = new StringBuilder(b.length * (2 + 1));
Formatter formatter = new Formatter(sb);
if (!reverse) {
for (int i = 0; i < b.length; i++) {
if (i < b.length - 1)
formatter.format("%02X:", b[i]);
else
formatter.format("%02X", b[i]);
}
} else {
for (int i = (b.length - 1); i >= 0; i--) {
if (i > 0)
formatter.format("%02X:", b[i]);
else
formatter.format("%02X", b[i]);
}
}
formatter.close();
return sb.toString();
}