/** * Parsing method for metafile headers, saving each value into separate variable. * * @param s String containing metafile * @return Boolean value notifying whether header ended or not (true = end of header) */ private boolean parseHeader(String s) { String subs; int colonIndex; if (s.equals("")) { // timto prazdnym radkem skoncil header, muzeme prestat cist return true; } colonIndex = s.indexOf(":"); subs = s.substring(0, colonIndex); if (subs.equalsIgnoreCase("zsync")) { headers.version = s.substring(colonIndex + 2); // zkontrolujeme kompatibilitu if (headers.version.equals("0.0.4") || headers.version.equals("0.0.2")) { throw new RuntimeException( "This version is not compatible with zsync streams in versions up to 0.0.4"); } } else if (subs.equalsIgnoreCase("Blocksize")) { headers.blocksize = Integer.parseInt(s.substring(colonIndex + 2)); } else if (subs.equalsIgnoreCase("Length")) { headers.length = Long.parseLong(s.substring(colonIndex + 2)); } else if (subs.equalsIgnoreCase("Hash-Lengths")) { int comma = s.indexOf(","); int seqNum = Integer.parseInt(s.substring((colonIndex + 2), comma)); headers.setSeqNum(seqNum); int nextComma = s.indexOf(",", comma + 1); headers.setRsumBytes(Integer.parseInt(s.substring(comma + 1, nextComma))); headers.setChecksumBytes(Integer.parseInt(s.substring(nextComma + 1))); if ((headers.getSeqNum() < 1 || headers.getSeqNum() > 2) || (headers.getRsumButes() < 1 || headers.getRsumButes() > 4) || (headers.getChecksumBytes() < 3 || headers.getChecksumBytes() > 16)) { throw new RuntimeException("Nonsensical hash lengths line " + s.substring(colonIndex + 2)); } } else if (subs.equalsIgnoreCase("URL")) { headers.url = s.substring(colonIndex + 2); } else if (subs.equalsIgnoreCase("Z-URL")) { // not implemented yet } else if (subs.equalsIgnoreCase("SHA-1")) { headers.sha1 = s.substring(colonIndex + 2); } else if (subs.equalsIgnoreCase("Z-Map2")) { // not implemented yet } return false; }