本文整理汇总了Java中java.util.Formatter.ioException方法的典型用法代码示例。如果您正苦于以下问题:Java Formatter.ioException方法的具体用法?Java Formatter.ioException怎么用?Java Formatter.ioException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Formatter
的用法示例。
在下文中一共展示了Formatter.ioException方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printf
import java.util.Formatter; //导入方法依赖的package包/类
static void printf(Formatter formatter, String format, Object... args) throws IOException {
formatter.format(format, args);
IOException ioException = formatter.ioException();
if (ioException != null) {
throw ioException;
}
}
示例2: saveModel
import java.util.Formatter; //导入方法依赖的package包/类
/**
* Writes the model to the modelOutput. It uses {@link java.util.Locale#ENGLISH} for number
* formatting.
*
* <p>
* <b>Note: The modelOutput is closed after reading or in case of an exception.</b>
* </p>
*/
public static void saveModel(Writer modelOutput, Model model) throws IOException {
int nr_feature = model.nr_feature;
int w_size = nr_feature;
if (model.bias >= 0) {
w_size++;
}
int nr_w = model.nr_class;
if (model.nr_class == 2 && model.solverType != SolverType.MCSVM_CS) {
nr_w = 1;
}
Formatter formatter = new Formatter(modelOutput, DEFAULT_LOCALE);
try {
printf(formatter, "solver_type %s\n", model.solverType.name());
printf(formatter, "nr_class %d\n", model.nr_class);
if (model.label != null) {
printf(formatter, "label");
for (int i = 0; i < model.nr_class; i++) {
printf(formatter, " %d", model.label[i]);
}
printf(formatter, "\n");
}
printf(formatter, "nr_feature %d\n", nr_feature);
printf(formatter, "bias %.16g\n", model.bias);
printf(formatter, "w\n");
for (int i = 0; i < w_size; i++) {
for (int j = 0; j < nr_w; j++) {
double value = model.w[i * nr_w + j];
/** this optimization is the reason for {@link Model#equals(double[], double[])} */
if (value == 0.0) {
printf(formatter, "%d ", 0);
} else {
printf(formatter, "%.16g ", value);
}
}
printf(formatter, "\n");
}
formatter.flush();
IOException ioException = formatter.ioException();
if (ioException != null) {
throw ioException;
}
} finally {
formatter.close();
}
}