当前位置: 首页>>代码示例>>Java>>正文


Java Formatter.format方法代码示例

本文整理汇总了Java中java.util.Formatter.format方法的典型用法代码示例。如果您正苦于以下问题:Java Formatter.format方法的具体用法?Java Formatter.format怎么用?Java Formatter.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Formatter的用法示例。


在下文中一共展示了Formatter.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet

import java.util.Formatter; //导入方法依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{

    // create a new formatter
    StringBuffer buffer = new StringBuffer();
    Formatter formatter = new Formatter(buffer, Locale.US);
    String format = "The customer: %s %s" + request.getParameter("suffix");

    //test cases
    formatter.format(format, "John", "Smith", "Jr"); //BAD
    formatter.format(Locale.US, format, "John", "Smith"); //BAD
    //false positive test
    formatter.format("The customer: %s %s", "John", request.getParameter("testParam")); //OK
    
    System.out.printf(format, "John", "Smith"); //BAD
    System.out.printf(Locale.US, format, "John", "Smith"); //BAD

    System.out.format(format, "John", "Smith"); //BAD
    System.out.format(Locale.US, format, "John", "Smith"); //BAD

    String.format(format, "John", "Smith"); //BAD
    String.format(Locale.US, format, "John", "Smith"); //BAD

    }
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:24,代码来源:FormatStringManipulation.java

示例2: 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 %10d %19d%n", numRows, numColumns,
            Matrices.cardinality(this));

    int i = 0;
    for (MatrixEntry e : this) {
        if (e.get() != 0)
            out.format("%10d %10d % .12e\n", e.row() + 1, e.column() + 1,
                    e.get());
        if (++i == 100) {
            out.format("...\n");
            break;
        }
    }

    return out.toString();
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:22,代码来源:AbstractMatrix.java

示例3: buildSensorControlCommand

import java.util.Formatter; //导入方法依赖的package包/类
/**
 * build TDV string of the sensor control command
 * @param info     sensor info
 * @param value    command value
 * @return TDV command string
 */
public static String buildSensorControlCommand(SensorInfo info, int value) {
    Formatter formatter = new Formatter();
    formatter.format("%02x", info.getType().getValueTDVTypes()[0]);
    switch (info.getType()) {
        case BUZZER:
            formatter.format("%02x", ValueType.UCHAR.getCode());
            formatter.format("%02x", value);
            break;
        case LED:
            formatter.format("%02x", ValueType.CHAR3.getCode());
            formatter.format("%06x", value);
            break;
        default:
            formatter.format("%02x", ValueType.BOOL.getCode());
            formatter.format("%02x", value);
            break;
    }
    String result = formatter.toString();
    formatter.close();
    return result;
}
 
开发者ID:SKT-ThingPlug,项目名称:thingplug-sdk-android,代码行数:28,代码来源:TDVBuilder.java

示例4: formatInjectionPoint

import java.util.Formatter; //导入方法依赖的package包/类
public static void formatInjectionPoint(Formatter formatter, Dependency<?> dependency,
    InjectionPoint injectionPoint, ElementSource elementSource) {
  Member member = injectionPoint.getMember();
  Class<? extends Member> memberType = Classes.memberType(member);

  if (memberType == Field.class) {
    dependency = injectionPoint.getDependencies().get(0);
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for field at %s%n", StackTraceElements.forMember(member));

  } else if (dependency != null) {
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for %s%n", formatParameter(dependency));

  } else {
    formatSource(formatter, injectionPoint.getMember());
  }
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:19,代码来源:Errors.java

示例5: dumpSerialStream

import java.util.Formatter; //导入方法依赖的package包/类
/**
 * Utility method to dump a byte array in a java syntax.
 * @param bytes and array of bytes
 * @return a string containing the bytes formatted in java syntax
 */
protected static String dumpSerialStream(byte[] bytes) {
    StringBuilder sb = new StringBuilder(bytes.length * 5);
    Formatter fmt = new Formatter(sb);
    fmt.format("    byte[] bytes = {" );
    final int linelen = 10;
    for (int i = 0; i < bytes.length; i++) {
        if (i % linelen == 0) {
            fmt.format("%n        ");
        }
        fmt.format(" %3d,", bytes[i] & 0xff);
        if ((i % linelen) == (linelen-1) || i == bytes.length - 1) {
            fmt.format("  /*");
            int s = i / linelen * linelen;
            int k = i % linelen;
            for (int j = 0; j <= k && s + j < bytes.length; j++) {
                fmt.format(" %c", bytes[s + j] & 0xff);
            }
            fmt.format(" */");
        }
    }
    fmt.format("%n    };%n");
    return sb.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:AbstractTCKTest.java

示例6: getRequiredCapability

import java.util.Formatter; //导入方法依赖的package包/类
/**
 * Gets a capability provided by the {@link GraalRuntime} instance available to the application.
 *
 * @throws UnsupportedOperationException if the capability is not available
 */
public static <T> T getRequiredCapability(Class<T> clazz) {
    T t = getRuntime().getCapability(clazz);
    if (t == null) {
        String javaHome = System.getProperty("java.home");
        String vmName = System.getProperty("java.vm.name");
        Formatter errorMessage = new Formatter();
        if (getRuntime().getClass() == InvalidGraalRuntime.class) {
            errorMessage.format("The VM does not support the Graal API.%n");
        } else {
            errorMessage.format("The VM does not expose required Graal capability %s.%n", clazz.getName());
        }
        errorMessage.format("Currently used Java home directory is %s.%n", javaHome);
        errorMessage.format("Currently used VM configuration is: %s", vmName);
        throw new UnsupportedOperationException(errorMessage.toString());
    }
    return t;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:Graal.java

示例7: bytesToString

import java.util.Formatter; //导入方法依赖的package包/类
public static String bytesToString(long bytes) {
	Formatter formatter = new Formatter();
	try {
		if (bytes > 1024) {
			if (bytes > 1024L * 1024L) {
				if (bytes > 1024L * 1024L * 1024L) {
					if (bytes > 1024L * 1024L * 1024L * 1024L) {
						return formatter.format("%9.2f", ((float) bytes / (float) (1024L * 1024L * 1024L * 1024L))) + " TB";
					} else {
						return formatter.format("%9.2f", (float) bytes / (float) (1024L * 1024L * 1024L)) + " GB";
					}
				} else {
					return formatter.format("%9.2f", ((float) bytes / (float) (1024L * 1024L))) + " MB";
				}
			} else {
				return formatter.format("%9.2f", ((float) bytes / (float) 1024L)) + " KB";
			}
		} else {
			return "" + bytes + " B";
		}
	} finally {
		formatter.close();
	}
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:25,代码来源:Formatters.java

示例8: formatSource

import java.util.Formatter; //导入方法依赖的package包/类
public static void formatSource(Formatter formatter, Object source, ElementSource elementSource) {
  String modules = moduleSourceString(elementSource);
  if (source instanceof Dependency) {
    Dependency<?> dependency = (Dependency<?>) source;
    InjectionPoint injectionPoint = dependency.getInjectionPoint();
    if (injectionPoint != null) {
      formatInjectionPoint(formatter, dependency, injectionPoint, elementSource);
    } else {
      formatSource(formatter, dependency.getKey(), elementSource);
    }

  } else if (source instanceof InjectionPoint) {
    formatInjectionPoint(formatter, null, (InjectionPoint) source, elementSource);

  } else if (source instanceof Class) {
    formatter.format("  at %s%s%n", StackTraceElements.forType((Class<?>) source), modules);

  } else if (source instanceof Member) {
    formatter.format("  at %s%s%n", StackTraceElements.forMember((Member) source), modules);

  } else if (source instanceof TypeLiteral) {
    formatter.format("  while locating %s%s%n", source, modules);

  } else if (source instanceof Key) {
    Key<?> key = (Key<?>) source;
    formatter.format("  while locating %s%n", convert(key, elementSource));

  } else if (source instanceof Thread) {
    formatter.format("  in thread %s%n", source);

  } else {
    formatter.format("  at %s%s%n", source, modules);
  }
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:35,代码来源:Errors.java

示例9: byteToHex

import java.util.Formatter; //导入方法依赖的package包/类
private static String byteToHex(final byte[] hash) {
    Formatter formatter = new Formatter();
    for (byte b : hash)
    {
        formatter.format("%02x", b);
    }
    String result = formatter.toString();
    formatter.close();
    return result;
}
 
开发者ID:Yunfeng,项目名称:weixinpay,代码行数:11,代码来源:SignUtil.java

示例10: formatTo

import java.util.Formatter; //导入方法依赖的package包/类
@Override
public void formatTo(Formatter formatter, int flags, int width, int precision) {
    if ((flags & ALTERNATE) == 0) {
        formatter.format(applyFormattingFlagsAndWidth(toString(), flags, width));
    } else {
        StringBuilder sb = new StringBuilder();
        sb.append(info.method.getName()).append('(');
        String sep = "";
        for (int i = 0; i < info.getParameterCount(); i++) {
            if (info.isConstantParameter(i)) {
                sb.append(sep);
                if (info.getParameterName(i) != null) {
                    sb.append(info.getParameterName(i));
                } else {
                    sb.append(i);
                }
                sb.append('=').append(values[i]);
                sep = ", ";
            }
        }
        sb.append(")");
        String string = sb.toString();
        if (string.indexOf('%') != -1) {
            // Quote any % signs
            string = string.replace("%", "%%");
        }
        formatter.format(applyFormattingFlagsAndWidth(string, flags & ~ALTERNATE, width));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:SnippetTemplate.java

示例11: toString

import java.util.Formatter; //导入方法依赖的package包/类
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb, Locale.US);
    f.format("=== Types ===%n");
    f.format("%s%n", types.toString());
    f.format("=== Methods ===%n");
    f.format("%s%n", methods.toString());
    f.format("=== Fields ===%n");
    f.format("%s%n", fields.toString());
    return sb.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:DeprDB.java

示例12: bytesToHexString

import java.util.Formatter; //导入方法依赖的package包/类
public static String bytesToHexString(byte[] bytes) {
    StringBuilder sb = new StringBuilder(bytes.length * 2);
    Formatter formatter = new Formatter(sb);
    for (byte b : bytes) {
        formatter.format("%02x", b);
    }
    formatter.close();
    return sb.toString();
}
 
开发者ID:AlexeyZatsepin,项目名称:CP-Tester,代码行数:10,代码来源:ContentProviderHelper.java

示例13: BytetohexString

import java.util.Formatter; //导入方法依赖的package包/类
public static String BytetohexString(byte[] b, int len) {
    StringBuilder sb = new StringBuilder(b.length * (2 + 1));
    Formatter formatter = new Formatter(sb);

    for (int i = 0; i < len; i++) {
        if (i < len - 1)
            formatter.format("%02X:", b[i]);
        else
            formatter.format("%02X", b[i]);

    }
    formatter.close();

    return sb.toString();
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:16,代码来源:Conversion.java

示例14: doStepInternal

import java.util.Formatter; //导入方法依赖的package包/类
protected void doStepInternal() {
    try {
       
        Formatter formatter = new Formatter("energy-"+fileTail);
        Vector pos = adatom.getPosition();
        // Move atom along Y-axis, steps by 0.1
        for(int i=0; i<292; i++){ //292
            
            // Return atom to original Z position
            adatom.getPosition().setX(2, -1.6);
            
            // Move atom along Z-axis, steps by 0.1
            for(int j=0; j<213; j++){  //213
                // --PRINT-- 
                formatter.format("%f %7.2f %7.2f %7.2f \n",new Object[] {energy.getDataAsScalar(),pos.getX(0), pos.getX(1), pos.getX(2)});
                
                // Step atom by 0.1 along Z-axis
                adatom.getPosition().setX(2, adatom.getPosition().getX(2) +0.02);
            }
            // Step atom by 0.1 along Y-axis
            adatom.getPosition().setX(1, adatom.getPosition().getX(1) + 0.02);
 
        }
        formatter.close();
    }
    catch (IOException e) {
        
    }
}
 
开发者ID:etomica,项目名称:etomica,代码行数:30,代码来源:IntegratorEnergyMap.java

示例15: toHexString

import java.util.Formatter; //导入方法依赖的package包/类
private static String toHexString(byte[] bytes) {
    Formatter formatter = new Formatter();

    for (byte b : bytes) {
        formatter.format("%02x", b);
    }

    return formatter.toString();
}
 
开发者ID:ukevgen,项目名称:BizareChat,代码行数:10,代码来源:HmacSha1Signature.java


注:本文中的java.util.Formatter.format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。