use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.
the class FileTypeReader method getFileType.
@MaybeNull
public static FileType getFileType(InputStream inputStream) throws IOException {
// create buffered stream for reuse
BufferedInputStream bis = new BufferedInputStream(inputStream);
bis.mark();
// read first two characters. if "PK", we have a compressed MusicXML file.
int[] bytes = new int[] { bis.read(), bis.read() };
if (// P, K
bytes[0] == 80 && bytes[1] == 75) {
return FileType.Compressed;
}
bis.reset();
bis.unmark();
// otherwise, try to parse as XML up to the root element (using StAX)
try {
XmlReader reader = platformUtils().createXmlReader(bis);
if (reader.openNextChildElement()) {
String n = reader.getElementName();
switch(n) {
case "score-partwise":
return FileType.XMLScorePartwise;
case "score-timewise":
return FileType.XMLScoreTimewise;
case "opus":
return FileType.XMLOpus;
}
reader.closeElement();
}
} catch (XmlException ex) {
// unknown (no XML)
return null;
}
// unknown
return null;
}
use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.
the class FontInfoReader method read.
@MaybeNull
public FontInfo read() {
IList<String> families = readFamilies();
Float size = readSize();
FontStyle style = readStyle();
return new FontInfo(families, size, style);
}
use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.
the class MxlFermata method read.
/**
* Reads the given element and returns it, or returns null if
* the element is not supported.
*/
@MaybeNull
public static MxlFermata read(XmlReader reader) {
MxlUprightInverted type = MxlUprightInverted.read(reader, "type");
MxlPrintStyle printStyle = MxlPrintStyle.read(reader);
return new MxlFermata(type, printStyle);
}
use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.
the class MxlDefaults method read.
@MaybeNull
public static MxlDefaults read(XmlReader reader) {
MxlScaling scaling = null;
MxlLayout layout = new MxlLayout();
MxlFont wordFont = null;
MxlLyricFont lyricFont = null;
while (reader.openNextChildElement()) {
String n = reader.getElementName();
if (n.equals(MxlScaling.elemName))
scaling = MxlScaling.read(reader);
else if (n.equals("word-font"))
wordFont = MxlFont.read(reader);
else if (// read only first
n.equals(MxlLyricFont.elemName) && lyricFont == null)
lyricFont = MxlLyricFont.read(reader);
else
layout.readElement(reader);
reader.closeElement();
}
if (false == layout.isUsed())
layout = null;
if (scaling != null || layout != null || wordFont != null || lyricFont != null)
return new MxlDefaults(scaling, layout, wordFont, lyricFont);
else
return null;
}
use of com.xenoage.utils.annotations.MaybeNull in project Zong by Xenoage.
the class MxlKey method read.
/**
* Returns null, if the key is unsupported.
*/
@MaybeNull
public static MxlKey read(XmlReader reader) {
Integer fifths = null;
MxlMode mode = null;
while (reader.openNextChildElement()) {
String eName = reader.getElementName();
if (eName.equals("fifths")) {
fifths = Parser.parseIntegerNull(reader.getText());
} else if (eName.equals(MxlMode.elemName)) {
mode = MxlMode.read(reader);
}
reader.closeElement();
}
if (fifths != null)
return new MxlKey(fifths, mode);
else
return null;
}
Aggregations