/** * Returns the Loop in X12 {@link java.lang.String} format. This method is used to convert the X12 * object into a X12 transaction. * * @param bRemoveTrailingEmptyElements a flag for whether or not empty trailing elements should be * removed. * @return String representation of the loop. */ public String toString(boolean bRemoveTrailingEmptyElements) { StringBuilder dump = new StringBuilder(); for (Segment s : this.segments) { dump.append(s.toString(bRemoveTrailingEmptyElements)); dump.append(context.getSegmentSeparator()); } for (Loop l : this.childList()) { dump.append(l.toString(bRemoveTrailingEmptyElements)); } return dump.toString(); }
public static void main(String[] args) throws Exception { String sourceUrlString = "data/test.html"; if (args.length == 0) System.err.println("Using default argument of \"" + sourceUrlString + '"'); else sourceUrlString = args[0]; if (sourceUrlString.indexOf(':') == -1) sourceUrlString = "file:" + sourceUrlString; StreamedSource streamedSource = new StreamedSource(new URL(sourceUrlString)); // streamedSource.setBuffer(new char[65000]); // uncomment this to use a fixed buffer size Writer writer = null; try { writer = new OutputStreamWriter( new FileOutputStream("StreamedSourceCopyOutput.html"), streamedSource.getEncoding()); System.out.println("Processing segments:"); int lastSegmentEnd = 0; for (Segment segment : streamedSource) { System.out.println(segment.getDebugInfo()); if (segment.getEnd() <= lastSegmentEnd) continue; // if this tag is inside the previous tag (e.g. a server tag) then ignore it as // it was already output along with the previous tag. lastSegmentEnd = segment.getEnd(); if (segment instanceof Tag) { Tag tag = (Tag) segment; // HANDLE TAG // Uncomment the following line to ensure each tag is valid XML: // writer.write(tag.tidy()); continue; } else if (segment instanceof CharacterReference) { CharacterReference characterReference = (CharacterReference) segment; // HANDLE CHARACTER REFERENCE // Uncomment the following line to decode all character references instead of copying them // verbatim: // characterReference.appendCharTo(writer); continue; } else { // HANDLE PLAIN TEXT } // unless specific handling has prevented getting to here, simply output the segment as is: writer.write(segment.toString()); } writer.close(); System.err.println( "\nA copy of the source document has been output to StreamedSourceCopyOuput.html"); } catch (Exception ex) { if (writer != null) try { writer.close(); } catch (IOException ex2) { } throw ex; } }
public String toString() { StringBuilder sb = new StringBuilder(); String showName = MediaFileAPI.GetMediaTitle(mediaFile); int numberOfMediaFileSegments = MediaFileAPI.GetNumberOfSegments(mediaFile); int segmentCount = (isFileCurrentlyRecording) ? segmentList.size() - 1 : segmentList.size(); Log.debug("Show: " + showName); Log.debug("MediaFileId: " + mediaFileId); Log.debug("Number Of MediaFile segments: " + numberOfMediaFileSegments); Log.debug("Is file currently recording: " + isFileCurrentlyRecording); Log.debug("Number of playlist segments: " + segmentCount); sb.append("#EXTM3U" + LINE_TERM); Log.debug("#EXTM3U"); sb.append("#EXT-X-TARGETDURATION:" + TARGET_DURATION + LINE_TERM); Log.debug("#EXT-X-TARGETDURATION:" + SegmentPlaylist.TARGET_DURATION); // sb.append("#EXT-X-MEDIA-SEQUENCE:1" + LINE_TERM); // Log.debug("#EXT-X-MEDIA-SEQUENCE:1"); for (int i = 0; i < segmentCount; i++) { Segment currentSegment = segmentList.get(i); Segment previousSegment = (i == 0) ? null : segmentList.get(i - 1); Segment nextSegment = (i == segmentCount - 1) ? null : segmentList.get(i + 1); String str = currentSegment.toString(); sb.append(str); // first or last playlist segment for each media file segment // printing the whole playlist makes the log harder to read if ((previousSegment == null) || (nextSegment == null) || (previousSegment.mediaFileSegment != currentSegment.mediaFileSegment) || (currentSegment.mediaFileSegment != nextSegment.mediaFileSegment)) { Log.debug(str); } } // #EXT-X-MEDIA-SEQUENCE:<number> // #EXT-X-PROGRAM-DATE-TIME:<YYYY-MM-DDThh:mm:ssZ> // #EXT-X-ALLOW-CACHE:<YES|NO> // #EXT-X-STREAM-INF if (!isFileCurrentlyRecording) { sb.append("#EXT-X-ENDLIST" + LINE_TERM); Log.debug("#EXT-X-ENDLIST"); } return sb.toString(); }
/** * Appends the given {@link Segment} to the output. * * @param segment The {@link Segment}, that should be appended to the output. */ protected void append(Segment segment) { this.sb.append(segment.toString()); }
private void dnaCommand(HttpServletRequest req, DazzleResponse resp, DazzleDataSource dds) throws IOException, DataSourceException, ServletException, DazzleException { DazzleReferenceSource drs = (DazzleReferenceSource) dds; List segments = DazzleTools.getSegments(dds, req, resp); if (segments.size() == 0) { throw new DazzleException( DASStatus.STATUS_BAD_COMMAND_ARGUMENTS, "No segments specified for dna command"); } // Fetch and validate the requests. Map segmentResults = new HashMap(); for (Iterator i = segments.iterator(); i.hasNext(); ) { Segment seg = (Segment) i.next(); try { Sequence seq = drs.getSequence(seg.getReference()); if (seq.getAlphabet() != DNATools.getDNA()) { throw new DazzleException( DASStatus.STATUS_SERVER_ERROR, "Sequence " + seg.toString() + " is not in the DNA alphabet"); } if (seg.isBounded()) { if (seg.getMin() < 1 || seg.getMax() > seq.length()) { throw new DazzleException( DASStatus.STATUS_BAD_COORDS, "Segment " + seg.toString() + " doesn't fit sequence of length " + seq.length()); } } segmentResults.put(seg, seq); } catch (NoSuchElementException ex) { throw new DazzleException(DASStatus.STATUS_BAD_REFERENCE, ex); } catch (DataSourceException ex) { throw new DazzleException(DASStatus.STATUS_SERVER_ERROR, ex); } } // // Looks okay -- generate the response document // XMLWriter xw = resp.startDasXML("DASDNA", "dasdna.dtd"); try { xw.openTag("DASDNA"); for (Iterator i = segmentResults.entrySet().iterator(); i.hasNext(); ) { Map.Entry me = (Map.Entry) i.next(); Segment seg = (Segment) me.getKey(); Sequence seq = (Sequence) me.getValue(); xw.openTag("SEQUENCE"); xw.attribute("id", seg.getReference()); xw.attribute("version", drs.getLandmarkVersion(seg.getReference())); if (seg.isBounded()) { xw.attribute("start", "" + seg.getStart()); xw.attribute("stop", "" + seg.getStop()); } else { xw.attribute("start", "" + 1); xw.attribute("stop", "" + seq.length()); } SymbolList syms = seq; if (seg.isBounded()) { syms = syms.subList(seg.getMin(), seg.getMax()); } if (seg.isInverted()) { syms = DNATools.reverseComplement(syms); } xw.openTag("DNA"); xw.attribute("length", "" + syms.length()); for (int pos = 1; pos <= syms.length(); pos += 60) { int maxPos = Math.min(syms.length(), pos + 59); xw.println(syms.subStr(pos, maxPos)); } xw.closeTag("DNA"); xw.closeTag("SEQUENCE"); } xw.closeTag("DASDNA"); xw.close(); } catch (Exception ex) { throw new DazzleException(ex, "Error writing DNA document"); } }