Read yaml file in java [duplicate] - java

This question already has an answer here:
How do you actually parse values in YAML in Java? [duplicate]
(1 answer)
Closed 6 years ago.
I want to write java program to read set of data from YAML file in cloud foundry.
#Define CDN domains
---
domains:
name : CDN1
quality : 200..300
cost : low
location: http://
name: CDN2
quality: 400..500
cost: high
location: http://
Then, in the program based on the name and quality it should redirect the first request to new location.
Can anyone help me for this?
I`m entirely new in YAML!
Based on my search, I can use snacked YAML or bean YAML, but I don't know what difference is.

You can use Jackson to read YAML, which is widely supported in Spring: https://github.com/FasterXML/jackson-dataformat-yaml

Related

Get values froma a Dataset<Row> into a .txt file (using Java) [duplicate]

This question already has answers here:
Write/store dataframe in text file
(5 answers)
Closed 4 years ago.
Im new here so i hope to help you and be helped if could be possible.
I made a Apache Spark project using Spark SQL and ML Spark in Java. I've finished this project but i have some problems with the output.
I've got a Dataset<Row> final (final is the name of the dataset) with some information. When i use show() with this dataset ( finals.show(); ) I get the next information:
[2018026,1,9.93,127.66,5.16,245.8,4.426875,6.91]
[2018026,1,9.97,127.89,5.36,244.8,4.426875,6.91]
[2018026,1,6.76,113.54,6.42,228.8,4.426875,6.91]
[2018026,1,6.92,114.2,6.81,224.0,4.426875,6.91]
[2018026,1,6.86,113.98,6.65,226.0,4.426875,6.91]
[2018026,1,6.81,113.76,6.58,227.4,4.426875,6.91]
[2018026,1,6.97,113.49,6.58,225.8,4.426875,6.91]
[2018026,1,6.97,114.42,6.67,221.6,4.426875,6.91]
(The "," is the separator between the fields).
Well, I'm trying to get this output in text file, for example projectSpark.txt but is impossible to me. How can I get this info on a text file?
Should I iterate over the Dataset<Row> or are there some methods to do this?
Thank so much guys.
Regards.
In Java, you can do something like it:
finals.javaRDD().map(x -> x.toString()).saveAsTextFile("your/path");
It will save your dataset in a single text file.

header value in regex expression for apache camel [duplicate]

This question already has an answer here:
How do dynamic "from" endpoints and exchanges work in camel?
(1 answer)
Closed 6 years ago.
I want to read files from a folder that correspond to a regex like this
from("direct:queuealpha").process(new DateTagGenerator()).from("file:///folder1/folder2/?delete=false&include=.*(${headers.timetag}).*);
So DateTagGenerator sets a header with a value I want to use in the regex as input. I tried escaping {, $ and } as well as using simple but I am obviously doing sth wrong.
How can I dynamically create a value for a header or the body, which can then be used for a regex?
Since Camel 2.16 you can use the Content Enricher with dynamic endpoints ([doc][1]) and in particular the pollEnrich (as you are using a file endpont)
from("direct:queuealpha")
.process(new DateTagGenerator())
.pollEnrich.simple("file:/folder1/folder2/?delete=false&include=${headers.timetagExpr}")
.process(…) // you can now process the message
.to(…); // and send it onward

Read a text file with Java [duplicate]

This question already has answers here:
Reading text file always returns 0 - Java
(2 answers)
Closed 7 years ago.
I have a game client jar that has an updater. Its client.jar and it downloads a cache which has all the game files. There is no need to update the client.jar just the cache, but the problem is the version number is hardcoded into the client.
What I've been trying to do ALL day is change the way the version number is obtained, and I just can't get it.
http://pastebin.com/Z5urTUVw
Line 31 is the version number, I need that to read a version number from a dropbox link. Found here - https://dl.dropboxusercontent.com/u/87363031/version.txt
Just 1 simple number, I've been trying to do this for the better part of 6 hours now and I'm bout to lose my cool. Can someone please help me with this?
If you can use Apache Commons IO, there's a very simple way to achieve this using IOUtils:
InputStream in = new URL("https://dl.dropboxusercontent.com/u/87363031/version.txt").openStream();
try {
String version = IOUtils.toString(in));
System.out.println(version);
} finally {
IOUtils.closeQuietly(in);
}

How do I rewrite a URI to a destination with a query string [duplicate]

This question already has answers here:
How do I preserve the existing query string in a mod_rewrite rule
(2 answers)
Closed 8 years ago.
We are trying to redirect bin-ends2 to wines.jsp with a number of parameters passed over to the application server. Apache is stripping the parameters off and so the application server fdoes not know what yo put in the page. The Apache config is:
RewriteRule ^/wines/bin-ends2$ http://qa2:7025/wines/wines.jsp?Form=WinesSearch&type=binends [PT]
Does anyone know how to make this work?
You need to add QSA flag to your rule when you introduce new query string parameters and would like to preserve (better say, include) existing query string.
Your rule should be
RewriteRule ^/wines/bin-ends2$ http://qa2:7025/wines/wines.jsp?Form=WinesSearch&type=binends [QSA,PT]
Useful link: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsa

how to read a config file with sections using Java [duplicate]

This question already has answers here:
What is the easiest way to parse an INI file in Java?
(13 answers)
Closed 7 years ago.
Given a file containing this:
[upper]
a = A
b = B
[words]
1 = one
2 = two
How do I access these key/values with reference to their headers? Java's Properties() class only handles section-less files.
Use the ini4j library (tutorial linked): http://ini4j.sourceforge.net/tutorial/
If you are a fan of the Apache Commons offerings, they have a library just for you: Commons Configuration. Commons Configuration reads many more formats other than just the .INI style files.

Categories