コード例 #1
0
ファイル: FileTypeReader.java プロジェクト: JasonLil/Zong
 @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 (bytes[0] == 80 && bytes[1] == 75) // P, K
   {
     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();
       if (n.equals("score-partwise")) return FileType.XMLScorePartwise;
       else if (n.equals("score-timewise")) return FileType.XMLScoreTimewise;
       else if (n.equals("opus")) return FileType.XMLOpus;
       reader.closeElement();
     }
   } catch (XmlException ex) {
     // unknown (no XML)
     return null;
   }
   // unknown
   return null;
 }
コード例 #2
0
ファイル: ChordWidthsReader.java プロジェクト: JasonLil/Zong
 /** Reads a {@link ChordWidths} from the given {@link XmlReader} at the "chordwidths" element. */
 public static ChordWidths readChordWidths(XmlReader r) throws IOException {
   HashMap<String, Float> m = map();
   while (r.openNextChildElement()) {
     String n = r.getElementName();
     String width = r.getAttribute("width");
     if (width != null) {
       m.put(n, Float.parseFloat(width));
     }
     r.closeElement();
   }
   return new ChordWidths(
       v(m, "whole"),
       v(m, "half"),
       v(m, "quarter"),
       v(m, "dotGap"),
       v(m, "dot"),
       v(m, "accToNoteGap"),
       v(m, "accToAccGap"),
       v(m, "doubleSharp"),
       v(m, "sharp"),
       v(m, "natural"),
       v(m, "flat"),
       v(m, "doubleFlat"));
 }