1 /* 2 * $HeadURL:https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/ParserCursor.java $ 3 * $Revision:589325 $ 4 * $Date:2007-10-28 11:37:56 +0100 (Sun, 28 Oct 2007) $ 5 * 6 * ==================================================================== 7 * Licensed to the Apache Software Foundation (ASF) under one 8 * or more contributor license agreements. See the NOTICE file 9 * distributed with this work for additional information 10 * regarding copyright ownership. The ASF licenses this file 11 * to you under the Apache License, Version 2.0 (the 12 * "License"); you may not use this file except in compliance 13 * with the License. You may obtain a copy of the License at 14 * 15 * http://www.apache.org/licenses/LICENSE-2.0 16 * 17 * Unless required by applicable law or agreed to in writing, 18 * software distributed under the License is distributed on an 19 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 20 * KIND, either express or implied. See the License for the 21 * specific language governing permissions and limitations 22 * under the License. 23 * ==================================================================== 24 * 25 * This software consists of voluntary contributions made by many 26 * individuals on behalf of the Apache Software Foundation. For more 27 * information on the Apache Software Foundation, please see 28 * <http://www.apache.org/>. 29 * 30 */ 31 32 package org.apache.http.message; 33 34 import org.apache.http.util.CharArrayBuffer; 35 36 /** 37 * This class represents a context of a parsing operation: 38 * <ul> 39 * <li>the current position the parsing operation is expected to start at</li> 40 * <li>the bounds limiting the scope of the parsing operation</li> 41 * </ul> 42 * 43 * @author <a href="mailto:oleg at ural.com">Oleg Kalnichevski</a> 44 * 45 * @deprecated Please use {@link java.net.URL#openConnection} instead. 46 * Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a> 47 * for further details. 48 */ 49 @Deprecated 50 public class ParserCursor { 51 52 private final int lowerBound; 53 private final int upperBound; 54 private int pos; 55 ParserCursor(int lowerBound, int upperBound)56 public ParserCursor(int lowerBound, int upperBound) { 57 super(); 58 if (lowerBound < 0) { 59 throw new IndexOutOfBoundsException("Lower bound cannot be negative"); 60 } 61 if (lowerBound > upperBound) { 62 throw new IndexOutOfBoundsException("Lower bound cannot be greater then upper bound"); 63 } 64 this.lowerBound = lowerBound; 65 this.upperBound = upperBound; 66 this.pos = lowerBound; 67 } 68 getLowerBound()69 public int getLowerBound() { 70 return this.lowerBound; 71 } 72 getUpperBound()73 public int getUpperBound() { 74 return this.upperBound; 75 } 76 getPos()77 public int getPos() { 78 return this.pos; 79 } 80 updatePos(int pos)81 public void updatePos(int pos) { 82 if (pos < this.lowerBound) { 83 throw new IndexOutOfBoundsException(); 84 } 85 if (pos > this.upperBound) { 86 throw new IndexOutOfBoundsException(); 87 } 88 this.pos = pos; 89 } 90 atEnd()91 public boolean atEnd() { 92 return this.pos >= this.upperBound; 93 } 94 toString()95 public String toString() { 96 CharArrayBuffer buffer = new CharArrayBuffer(16); 97 buffer.append('['); 98 buffer.append(Integer.toString(this.lowerBound)); 99 buffer.append('>'); 100 buffer.append(Integer.toString(this.pos)); 101 buffer.append('>'); 102 buffer.append(Integer.toString(this.upperBound)); 103 buffer.append(']'); 104 return buffer.toString(); 105 } 106 107 } 108