Java Code Examples for java.util.Formatter#ioException()

The following examples show how to use java.util.Formatter#ioException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Linear.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
static void printf(Formatter formatter, String format, Object... args) throws IOException {
	formatter.format(format, args);
	IOException ioException = formatter.ioException();
	if (ioException != null) {
		throw ioException;
	}
}
 
Example 2
Source File: Linear.java    From MMDW with MIT License 4 votes vote down vote up
static void printf(Formatter formatter, String format, Object... args) throws IOException {
    formatter.format(format, args);
    IOException ioException = formatter.ioException();
    if (ioException != null) throw ioException;
}
 
Example 3
Source File: Linear.java    From MMDW with MIT License 4 votes vote down vote up
/**
 * 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();
    }
}
 
Example 4
Source File: Linear.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 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();
	}
}
 
Example 5
Source File: Linear.java    From ml-ease with Apache License 2.0 4 votes vote down vote up
static void printf(Formatter formatter, String format, Object... args) throws IOException {
    formatter.format(format, args);
    IOException ioException = formatter.ioException();
    if (ioException != null) throw ioException;
}
 
Example 6
Source File: Linear.java    From ml-ease with Apache License 2.0 4 votes vote down vote up
/**
 * 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);

        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();
    }
}