use of org.n52.janmayen.http.MediaType in project arctic-sea by 52North.
the class UVFEncoder method encodeToUvf.
private File encodeToUvf(ObservationStream observationStream, File tempDir, MediaType contentType) throws IOException, EncodingException {
List<OmObservation> mergeObservations = mergeTotoList(observationStream);
String ending = getLineEnding(contentType);
String filename = getFilename(mergeObservations);
File uvfFile = new File(tempDir, filename);
try (Writer fw = new OutputStreamWriter(new FileOutputStream(uvfFile), "UTF-8")) {
for (OmObservation o : mergeObservations) {
if (o.isSetValue() && !checkForSingleObservationValue(o.getValue()) && !checkForMultiObservationValue(o.getValue())) {
String errorMessage = String.format("The resulting values are not of numeric type " + "which is only supported by this encoder '%s'.", this.getClass().getName());
LOGGER.error(errorMessage);
throw new EncodingException(errorMessage);
}
/*
* HEADER: Metadata
*/
writeFunktionInterpretation(fw, o, ending);
writeIndex(fw, ending);
writeMessGroesse(fw, o, ending);
writeMessEinheit(fw, o, ending);
writeMessStellennummer(fw, o, ending);
writeMessStellenname(fw, o, ending);
/*
* HEADER: Lines 1 - 4
*/
writeLine1(fw, ending);
TimePeriod temporalBBox = getTemporalBBoxFromObservations(mergeObservations);
writeLine2(fw, o, temporalBBox, ending);
writeLine3(fw, o, ending);
writeLine4(fw, temporalBBox, ending);
/*
* Observation Data
*/
writeObservationValue(fw, o, ending);
}
}
return uvfFile;
}
use of org.n52.janmayen.http.MediaType in project arctic-sea by 52North.
the class MediaTypeTest method testCompatibleXmlTypes.
// @Test
// public void testUrn() {
// thrown.expect(IllegalArgumentException.class);
// MediaType.parse(OGCConstants.URN_IDENTIFIER_IDENTIFICATION);
// }
//
// @Test
// public void testOgcUrlUnknown() {
// thrown.expect(IllegalArgumentException.class);
// MediaType.parse(OGCConstants.UNKNOWN);
// }
//
// @Test
// public void testSensorMLUrl() {
// thrown.expect(IllegalArgumentException.class);
// MediaType.parse(SensorMLConstants.SENSORML_OUTPUT_FORMAT_URL);
// }
@Test
public void testCompatibleXmlTypes() {
MediaType applicationXml = MediaType.parse("application/xml");
MediaType textXml = MediaType.parse("text/xml");
MediaType textPlain = MediaType.parse("text/plain");
errors.checkThat(applicationXml.isCompatible(textXml), is(true));
errors.checkThat(textXml.isCompatible(applicationXml), is(true));
errors.checkThat(applicationXml.isCompatible(textPlain), is(false));
errors.checkThat(textXml.isCompatible(textPlain), is(false));
}
use of org.n52.janmayen.http.MediaType in project arctic-sea by 52North.
the class MediaTypeTest method applicationXmlWithQuotedParameter.
@Test
public void applicationXmlWithQuotedParameter() {
MediaType mt = MediaType.parse(" application/xml; a=\"asdf\"");
errors.checkThat(mt.getType(), is("application"));
errors.checkThat(mt.getSubtype(), is("xml"));
errors.checkThat(mt.getParameters().size(), is(1));
errors.checkThat(mt.getParameter("a").iterator().next(), is("asdf"));
}
use of org.n52.janmayen.http.MediaType in project arctic-sea by 52North.
the class MediaTypeTest method applicationXmlWithQAndFourSpace.
@Test
public void applicationXmlWithQAndFourSpace() {
MediaType mt = MediaType.parse("application/xml; q=1");
errors.checkThat(mt.getType(), is("application"));
errors.checkThat(mt.getSubtype(), is("xml"));
errors.checkThat(mt.getParameters().size(), is(1));
errors.checkThat(mt.getParameter("q").iterator().next(), is("1"));
}
use of org.n52.janmayen.http.MediaType in project arctic-sea by 52North.
the class MediaTypeTest method applicationXmlWithQuotedParameterWithUnescapedSlash.
@Test
public void applicationXmlWithQuotedParameterWithUnescapedSlash() {
MediaType mt = MediaType.parse("application/xml;a=\"a\\\\b\"");
errors.checkThat(mt.getType(), is("application"));
errors.checkThat(mt.getSubtype(), is("xml"));
errors.checkThat(mt.getParameters().size(), is(1));
errors.checkThat(mt.getParameter("a").size(), is(1));
errors.checkThat(mt.getParameter("a").iterator().next(), is("a\\b"));
}
Aggregations