本文整理匯總了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();
}