Skip to content

Commit

Permalink
YAML test base addition
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 25, 2024
1 parent 1ca2e8f commit 319ab77
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.fasterxml.jackson.dataformat.yaml;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

Expand Down Expand Up @@ -188,4 +190,25 @@ protected static String trimDocMarker(String doc)
}
return doc.trim();
}

protected byte[] readResource(String ref)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
final byte[] buf = new byte[4000];

try (InputStream in = getClass().getResourceAsStream(ref)) {
if (in != null) {
int len;
while ((len = in.read(buf)) > 0) {
bytes.write(buf, 0, len);
}
}
} catch (IOException e) {
throw new RuntimeException("Failed to read resource '"+ref+"': "+e);
}
if (bytes.size() == 0) {
throw new IllegalArgumentException("Failed to read resource '"+ref+"': empty resource?");
}
return bytes.toByteArray();
}
}

0 comments on commit 319ab77

Please sign in to comment.