use of java.io.UncheckedIOException in project ArachneCentralAPI by OHDSI.
the class AnalysisController method convertToMultipartFile.
private MultipartFile convertToMultipartFile(Resource resource) {
try {
String rootPath = ((ClassPathResource) resource).getPath();
String name = convertToUnixPath(rootPath.substring(rootPath.indexOf(CC_SQLS_DIR) + CC_SQLS_DIR.length() + 1));
return new MockMultipartFile(name, name, null, readResource(CC_SQLS_DIR + "/" + name));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of java.io.UncheckedIOException in project assertj-core by joel-costigliola.
the class Files method assertSameContentAs.
/**
* Asserts that the given files have same content. Adapted from <a
* href="http://junit-addons.sourceforge.net/junitx/framework/FileAssert.html" target="_blank">FileAssert</a> (from <a
* href="http://sourceforge.net/projects/junit-addons">JUnit-addons</a>.)
* @param info contains information about the assertion.
* @param actual the "actual" file.
* @param actualCharset {@link Charset} of the "actual" file.
* @param expected the "expected" file.
* @param expectedCharset {@link Charset} of the "actual" file.
* @throws NullPointerException if {@code expected} is {@code null}.
* @throws IllegalArgumentException if {@code expected} is not an existing file.
* @throws AssertionError if {@code actual} is {@code null}.
* @throws AssertionError if {@code actual} is not an existing file.
* @throws UncheckedIOException if an I/O error occurs.
* @throws AssertionError if the given files do not have same content.
*/
public void assertSameContentAs(AssertionInfo info, File actual, Charset actualCharset, File expected, Charset expectedCharset) {
verifyIsFile(expected);
assertIsFile(info, actual);
try {
List<Delta<String>> diffs = diff.diff(actual, actualCharset, expected, expectedCharset);
if (diffs.isEmpty())
return;
throw failures.failure(info, shouldHaveSameContent(actual, expected, diffs));
} catch (MalformedInputException e) {
try {
// MalformedInputException is thrown by readLine() called in diff
// compute a binary diff, if there is a binary diff, it it shows the offset of the malformed input
BinaryDiffResult binaryDiffResult = binaryDiff.diff(actual, readAllBytes(expected.toPath()));
if (binaryDiffResult.hasNoDiff()) {
// fall back to the UncheckedIOException : not throwing an error is wrong as there was one in the first place.
throw e;
}
throw failures.failure(info, shouldHaveBinaryContent(actual, binaryDiffResult));
} catch (IOException ioe) {
throw new UncheckedIOException(format(UNABLE_TO_COMPARE_FILE_CONTENTS, actual, expected), ioe);
}
} catch (IOException e) {
throw new UncheckedIOException(format(UNABLE_TO_COMPARE_FILE_CONTENTS, actual, expected), e);
}
}
use of java.io.UncheckedIOException in project junit5 by junit-team.
the class JUnitPlatformProvider method getConfigurationParameters.
private Map<String, String> getConfigurationParameters() {
String content = parameters.getProviderProperties().get(CONFIGURATION_PARAMETERS);
if (content == null) {
return emptyMap();
}
try (StringReader reader = new StringReader(content)) {
Map<String, String> result = new HashMap<>();
Properties props = new Properties();
props.load(reader);
props.stringPropertyNames().forEach(key -> result.put(key, props.getProperty(key)));
return result;
} catch (IOException ex) {
throw new UncheckedIOException("Error reading " + CONFIGURATION_PARAMETERS, ex);
}
}
use of java.io.UncheckedIOException in project spf4j by zolyfarkas.
the class MessageFormat method formatToCharacterIterator.
/**
* Formats an array of objects and inserts them into the <code>MessageFormat</code>'s pattern, producing an
* <code>AttributedCharacterIterator</code>. You can use the returned <code>AttributedCharacterIterator</code> to
* build the resulting String, as well as to determine information about the resulting String.
* <p>
* The text of the returned <code>AttributedCharacterIterator</code> is the same that would be returned by
* <blockquote>
* <code>{@link #format(java.lang.Object[], java.lang.StringBuffer, java.text.FieldPosition) format}(arguments, new
* StringBuffer(), null).toString()</code>
* </blockquote>
* <p>
* In addition, the <code>AttributedCharacterIterator</code> contains at least attributes indicating where text was
* generated from an argument in the <code>arguments</code> array. The keys of these attributes are of type
* <code>MessageFormat.Field</code>, their values are <code>Integer</code> objects indicating the index in the
* <code>arguments</code> array of the argument from which the text was generated.
* <p>
* The attributes/value from the underlying <code>Format</code> instances that <code>MessageFormat</code> uses will
* also be placed in the resulting <code>AttributedCharacterIterator</code>. This allows you to not only find where an
* argument is placed in the resulting String, but also which fields it contains in turn.
*
* @param arguments an array of objects to be formatted and substituted.
* @return AttributedCharacterIterator describing the formatted value.
* @exception NullPointerException if <code>arguments</code> is null.
* @exception IllegalArgumentException if an argument in the <code>arguments</code> array is not of the type expected
* by the format element(s) that use it.
* @since 1.4
*/
public AttributedCharacterIterator formatToCharacterIterator(@Nonnull Object arguments) {
StringBuilder result = new StringBuilder();
ArrayList<AttributedCharacterIterator> iterators = new ArrayList<>();
try {
subformat((Object[]) arguments, result, null, iterators);
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
if (iterators.isEmpty()) {
return createAttributedCharacterIterator("");
}
return new AttributedString(iterators.toArray(new AttributedCharacterIterator[iterators.size()])).getIterator();
}
use of java.io.UncheckedIOException in project spf4j by zolyfarkas.
the class Strings method decode.
@SuppressFBWarnings("SUA_SUSPICIOUS_UNINITIALIZED_ARRAY")
public static String decode(final CharsetDecoder cd, final byte[] ba, final int off, final int len) {
if (len == 0) {
return "";
}
int en = (int) (len * (double) cd.maxCharsPerByte());
char[] ca = TLScratch.getCharsTmp(en);
if (cd instanceof ArrayDecoder) {
int clen = ((ArrayDecoder) cd).decode(ba, off, len, ca);
return new String(ca, 0, clen);
}
cd.reset();
ByteBuffer bb = ByteBuffer.wrap(ba, off, len);
CharBuffer cb = CharBuffer.wrap(ca);
try {
CoderResult cr = cd.decode(bb, cb, true);
if (!cr.isUnderflow()) {
cr.throwException();
}
cr = cd.flush(cb);
if (!cr.isUnderflow()) {
cr.throwException();
}
} catch (CharacterCodingException x) {
throw new UncheckedIOException(x);
}
return new String(ca, 0, cb.position());
}
Aggregations