/** * Emit a "start" or "EOF" bumper as appropriate to prominently * indicate if page borders start- or end- of-file. * * @param pw PrintWriter * @param atTop boolean, true if at top of page */ protected void emitBumper(PrintWriter pw, boolean atTop) { if((!reversedOrder ^ atTop)&&(range.getMaximumLong()==file.length())) { pw.println("<span class='endBumper' style='font-weight:bold; color:white; background-color:#400'>«EOF»</span>"); return; } if((reversedOrder ^ atTop)&&(range.getMinimumLong()==0)) { pw.println("<span class='startBumper' style='font-weight:bold; color:white; background-color:#040'>«START»</span>"); } }
/** * <p>Tests whether the specified <code>number</code> occurs within * this range using <code>long</code> comparison.</p> * * <p><code>null</code> is handled and returns <code>false</code>.</p> * * @param number the number to test, may be <code>null</code> * @return <code>true</code> if the specified number occurs within this range */ public boolean containsNumber(Number number) { if (number == null) { return false; } return containsLong(number.longValue()); }
public static LongRange expandRange(LongRange range1, LongRange range2) { return new LongRange(Math.min(range1.getMinimumLong(), range2.getMinimumLong()), Math.max(range1.getMaximumLong(), range2.getMaximumLong())); }
@Override public void setStartRange(long begin, long end) throws IllegalArgumentException { if (begin > end) { throw new IllegalArgumentException("begin > end in range (begin, " + "end): (" + begin + ", " + end + ")"); } this.start = new LongRange(begin, end); }
/** * add range to process and add it (potentially altered) to result list of ranges. * * @param from range left boundary * @param to range right boundary */ public void addRange(long from, long to) { LongRange addedRange = new LongRange(from, to); Iterator<LongRange> it = disjointRanges.iterator(); while (it.hasNext()) { LongRange existingRange = it.next(); if (existingRange.overlapsRange(addedRange)) { it.remove(); addedRange = new LongRange(Math.min(addedRange.getMinimumLong(), existingRange.getMinimumLong()), Math.max(addedRange.getMaximumLong(), existingRange.getMaximumLong())); } } disjointRanges.add(addedRange); }
public static LongRange expandRange(LongRange range1, LongRange range2) { return new LongRange(Math.min(range1.getMinimumLong(), range2.getMinimumLong()), Math.max(range1.getMaximumLong(), range2.getMaximumLong())); }
@Override public void setFinishRange(long begin, long end) { if (begin > end) { throw new IllegalArgumentException("begin > end in range (begin, " + "end): (" + begin + ", " + end + ")"); } this.finish = new LongRange(begin, end); }
public static LongRange expandRange(LongRange range1, LongRange range2) { return new LongRange(Math.min(range1.getMinimumLong(), range2.getMinimumLong()), Math.max(range1.getMaximumLong(), range2.getMaximumLong())); }
/** * Actually read the requested lines, and reverses if appropriate. * * If at file start, refuses to show fewer lines than are possible * ('bounces' against start). * * @throws IOException */ protected void loadLines() throws IOException { this.file = fileRepresentation.getFile(); this.lines = new LinkedList<String>(); this.range = FileUtils.pagedLines(file, position, lineCount, lines, 128); // bounce against the front of the file: don't show runt (fewer // lines than requested) unless absolutely necessary) if(lines.size()<Math.abs(lineCount) && range.getMinimumLong() == 0 && range.getMaximumLong()<file.length()) { this.lines = new LinkedList<String>(); this.range = FileUtils.pagedLines(file, 0, Math.abs(lineCount), lines, 128); } if(reversedOrder) { Collections.reverse(lines); } }
@Override public void setFinishRange(long begin, long end) { if (begin > end) { throw new IllegalArgumentException("begin > end in range (begin, " + "end): (" + begin + ", " + end + ")"); } this.finish = new LongRange(begin, end); }
/** * <p>Tests whether the specified range occurs entirely within this range * using <code>long</code> comparison.</p> * * <p><code>null</code> is handled and returns <code>false</code>.</p> * * @param range the range to test, may be <code>null</code> * @return <code>true</code> if the specified range occurs entirely within this range * @throws IllegalArgumentException if the range is not of this type */ public boolean containsRange(Range range) { if (range == null) { return false; } return containsLong(range.getMinimumLong()) && containsLong(range.getMaximumLong()); }
@Override public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { super.init(source, options, env); if (options.containsKey(Constants.START_DATE) && options.containsKey(Constants.END_DATE)) { long start = Long.parseLong(options.get(Constants.START_DATE)); long end = Long.parseLong(options.get(Constants.END_DATE)); // The begin date from the query may be down to the second, for doing lookups in the index we want to use the day because // the times in the index table have been truncated to the day. start = DateUtils.truncate(new Date(start), Calendar.DAY_OF_MONTH).getTime(); if (start > end) throw new IllegalArgumentException("Start date comes after end date"); range = new LongRange(start, end); if (log.isDebugEnabled()) { log.debug("Set the date range to " + new Date(range.getMinimumLong()) + " to " + new Date(range.getMaximumLong())); } } else { throw new IllegalArgumentException("Both options must be set: " + Constants.START_DATE + " and " + Constants.END_DATE); } }
pw.print("<a href='"); pw.print(getControlUri( Math.min(file.length()-1, range.getMaximumLong()),Math.abs(lineCount),reversedOrder)); pw.println("'>‹ later</a>"); pw.println("bytes " +range.getMaximumLong() +"-"+range.getMinimumLong() +"/"+file.length() +" " +(int)(100*(range.getMaximumLong()/(float)file.length())) +"%"); pw.print("<a href='"); pw.print(getControlUri( Math.max(0, range.getMinimumLong()-1),-Math.abs(lineCount),reversedOrder)); pw.println("'>earlier ›</a>"); pw.print("<a href='"); pw.println("'>« start</a>"); pw.print("<a href='");pw.print(getControlUri( Math.max(0, range.getMinimumLong()-1),-Math.abs(lineCount),reversedOrder)); pw.println("'>‹ earlier</a>"); pw.println("bytes " +range.getMinimumLong() +"-"+range.getMaximumLong() +"/"+file.length() +" " +(int)(100*(range.getMaximumLong()/(float)file.length())) +"%"); pw.print("<a href='");
@Override public void setStartRange(long begin, long end) throws IllegalArgumentException { if (begin > end) { throw new IllegalArgumentException("begin > end in range (begin, " + "end): (" + begin + ", " + end + ")"); } this.start = new LongRange(begin, end); }
/** * <p>Tests whether the specified range overlaps with this range * using <code>long</code> comparison.</p> * * <p><code>null</code> is handled and returns <code>false</code>.</p> * * @param range the range to test, may be <code>null</code> * @return <code>true</code> if the specified range overlaps with this range */ public boolean overlapsRange(Range range) { if (range == null) { return false; } return range.containsLong(min) || range.containsLong(max) || containsLong(range.getMinimumLong()); }
private LongRange merge(LongRange range1, LongRange range2) { if (range1 == null) { return range2; } else if (range2 == null) { return range1; } else { long min = Math.min(range1.getMinimumLong(), range2.getMinimumLong()); long max = Math.max(range1.getMaximumLong(), range2.getMaximumLong()); return new LongRange(min, max); } }
/** * @param ranges ranges to process and add them (potentially altered) to result list of ranges. */ public void addRanges(List<LongRange> ranges) { for (LongRange range : ranges) { addRange(range.getMinimumLong(), range.getMaximumLong()); } }
private static LongRange pair(long from, long to) { return new LongRange(from, to); }
/** * <p>Tests whether the specified <code>number</code> occurs within * this range using <code>long</code> comparison.</p> * * <p><code>null</code> is handled and returns <code>false</code>.</p> * * @param number the number to test, may be <code>null</code> * @return <code>true</code> if the specified number occurs within this range */ public boolean containsNumber(Number number) { if (number == null) { return false; } return containsLong(number.longValue()); }
if(startPosition+bufferSize == fileEnd) { return new LongRange(fileEnd,fileEnd); } else { LongRange range = new LongRange(startPosition + firstLine, startPosition + partialLine); List<String> foundLines = IOUtils.readLines(new ByteArrayInputStream(buf,firstLine,partialLine-firstLine)); range, pagedLines(file, range.getMinimumLong()-1, signedDesiredLineCount+foundFullLines, lines, if(signedDesiredLineCount < 0 && range.getMaximumLong() < position) { if(signedDesiredLineCount > 0 && foundFullLines < desiredLineCount && range.getMaximumLong() < fileEnd) { range.getMaximumLong(), desiredLineCount - foundFullLines, lines,