Search in sources :

Example 1 with YamlReader

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);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) InputStreamReader(java.io.InputStreamReader) ConfigurationException(org.audit4j.core.exception.ConfigurationException) YamlReader(com.esotericsoftware.yamlbeans.YamlReader)

Example 2 with YamlReader

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);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) YamlReader(com.esotericsoftware.yamlbeans.YamlReader)

Example 3 with YamlReader

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with YamlReader

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;
}
Also used : MiniFacade(org.twak.viewTrace.facades.MiniFacade) ArrayList(java.util.ArrayList) IOException(java.io.IOException) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) ICanPaint(org.twak.utils.PaintThing.ICanPaint) Line(org.twak.utils.Line) Point2d(javax.vecmath.Point2d) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) MultiMap(org.twak.utils.collections.MultiMap)

Example 5 with YamlReader

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);
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) StringWriter(java.io.StringWriter) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Test(org.junit.Test)

Aggregations

YamlReader (com.esotericsoftware.yamlbeans.YamlReader)11 YamlException (com.esotericsoftware.yamlbeans.YamlException)5 InputStreamReader (java.io.InputStreamReader)5 Map (java.util.Map)4 FileReader (java.io.FileReader)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ConfigurationException (org.audit4j.core.exception.ConfigurationException)2 Test (org.junit.Test)2 YamlConfig (com.esotericsoftware.yamlbeans.YamlConfig)1 YamlWriter (com.esotericsoftware.yamlbeans.YamlWriter)1 File (java.io.File)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Point2d (javax.vecmath.Point2d)1