use of com.esotericsoftware.yamlbeans.YamlReader in project audit4j-core by audit4j.
the class YAMLConfigProvider method readConfig.
/**
* {@inheritDoc}
*
* @see org.audit4j.core.ConfigProvider#readConfig(java.io.InputStream)
*/
@SuppressWarnings("unchecked")
@Override
public T readConfig(InputStream fileAsStream) throws ConfigurationException {
InputStreamReader streamReader = new InputStreamReader(fileAsStream);
try {
YamlReader reader = new YamlReader(streamReader);
reader.getConfig().setClassTag(clazz.getSimpleName(), clazz);
return (T) reader.read();
} catch (YamlException e) {
throw new ConfigurationException("Configuration Exception", "CONF_002", e);
}
}
use of com.esotericsoftware.yamlbeans.YamlReader in project StreetComplete by westnordost.
the class CreditsFragment method readContributors.
private List<String> readContributors() {
try {
InputStream is = getResources().openRawResource(R.raw.credits_contributors);
YamlReader reader = new YamlReader(new InputStreamReader(is));
List<String> result = new ArrayList<>((List) reader.read());
result.add(getString(R.string.credits_and_more));
return result;
} catch (YamlException e) {
throw new RuntimeException(e);
}
}
use of com.esotericsoftware.yamlbeans.YamlReader in project StreetComplete by westnordost.
the class Abbreviations method parseConfig.
private void parseConfig(InputStream config) throws YamlException {
abbreviations = new HashMap<>();
YamlReader reader = new YamlReader(new InputStreamReader(config));
Map map = (Map) reader.read();
for (Object o : map.entrySet()) {
Map.Entry pair2 = (Map.Entry) o;
String abbreviation = ((String) pair2.getKey()).toLowerCase(locale);
String expansion = ((String) pair2.getValue()).toLowerCase(locale);
if (abbreviation.endsWith("$")) {
abbreviation = abbreviation.substring(0, abbreviation.length() - 1) + "\\.?$";
} else {
abbreviation += "\\.?";
}
if (abbreviation.startsWith("...")) {
abbreviation = "(\\w*)" + abbreviation.substring(3);
expansion = "$1" + expansion;
}
abbreviations.put(abbreviation, expansion);
}
}
use of com.esotericsoftware.yamlbeans.YamlReader in project chordatlas by twak.
the class FeatureCache method readFeatures.
public static ImageFeatures readFeatures(File fFolder, MegaFeatures megaFeatures) {
Line mega = new Line(megaFeatures.megafacade);
ImageFeatures out = new ImageFeatures();
out.mega = megaFeatures;
Line imageL = null;
out.miniFacades = new ArrayList();
{
if (Tweed.DATA == null)
out.ortho = new File(fFolder, RENDERED_IMAGE_PNG);
else
out.ortho = Paths.get(Tweed.DATA).relativize(new File(fFolder, RENDERED_IMAGE_PNG).toPath()).toFile();
File rectFile = new File(fFolder, "rectified.png");
if (rectFile.exists()) {
if (Tweed.DATA == null)
out.rectified = rectFile;
else
out.rectified = Paths.get(Tweed.DATA).relativize(rectFile.toPath()).toFile();
} else
out.rectified = out.ortho;
}
int imageWidth = out.getRectified().getWidth(), imageHeight = out.getRectified().getHeight();
double rectifiedToOrtho = out.getRectified().getWidth() / (double) out.getOrtho().getWidth();
{
List<String> lines = null;
try {
lines = Files.readAllLines(new File(fFolder, "meta.txt").toPath());
} catch (IOException e) {
System.err.println("failed to read metafile");
}
if (lines == null) {
System.out.println("warning, failed to read input files in " + fFolder);
imageL = new Line(0, 0, out.getRectified().getWidth() / FacadeTool.pixelsPerMeter, 0);
} else {
String plane = lines.get(1);
String[] pVals = plane.split(" ");
Point2d a = new Point2d(Float.parseFloat(pVals[0]), Float.parseFloat(pVals[1]));
Point2d b = new Point2d(Float.parseFloat(pVals[2]), Float.parseFloat(pVals[3]));
imageL = new Line(a, b);
}
}
out.start = mega.findPPram(imageL.start) * mega.length();
out.end = mega.findPPram(imageL.end) * mega.length();
try {
File yFile = new File(fFolder, PARAMETERS_YML);
if (yFile.exists()) {
YamlReader fromVision = new YamlReader(new FileReader(yFile));
Map m = (Map) fromVision.read();
List yamlFac = (List) m.get("facades");
double maxW = 0;
if (yamlFac != null) {
for (Object o : yamlFac) try {
MiniFacade mf = new MiniFacade(out, (Map) o, imageWidth / (rectifiedToOrtho * FacadeTool.pixelsPerMeter), imageHeight / FacadeTool.pixelsPerMeter, rectifiedToOrtho * FacadeTool.pixelsPerMeter, out.start);
if (!mf.invalid())
out.miniFacades.add(mf);
maxW = Math.max(maxW, (mf.left + mf.width - out.start));
} catch (Throwable th) {
System.out.println("while reading " + yFile);
th.printStackTrace();
}
}
} else
System.out.println("no parameters in " + fFolder);
} catch (Throwable e) {
e.printStackTrace();
}
return out;
}
use of com.esotericsoftware.yamlbeans.YamlReader in project yamlbeans by EsotericSoftware.
the class Issue37Test method test.
@Test
public void test() throws YamlException {
TestObject testObject = new TestObject();
testObject.sexType = SexType.FEMALE;
YamlConfig yamlConfig = new YamlConfig();
yamlConfig.setScalarSerializer(SexType.class, new SexTypeSerializer());
StringWriter sw = new StringWriter();
YamlWriter writer = new YamlWriter(sw, yamlConfig);
writer.write(testObject);
writer.close();
System.out.println(sw.toString());
assertEquals("!com.esotericsoftware.yamlbeans.issues.issue37.TestObject" + LINE_SEPARATOR + "sexType: female" + LINE_SEPARATOR, sw.toString());
YamlReader reader = new YamlReader(sw.toString(), yamlConfig);
TestObject obj = reader.read(TestObject.class);
assertEquals(SexType.FEMALE, obj.sexType);
}
Aggregations