コード例 #1
0
  /** @tests java.util.ArrayList#add(int, java.lang.Object) */
  public void test_addILjava_lang_Object() {
    // Test for method void java.util.ArrayList.add(int, java.lang.Object)
    Object o;
    alist.add(50, o = new Object());
    assertTrue("Failed to add Object", alist.get(50) == o);
    assertTrue(
        "Failed to fix up list after insert",
        alist.get(51) == objArray[50] && (alist.get(52) == objArray[51]));
    Object oldItem = alist.get(25);
    alist.add(25, null);
    assertNull("Should have returned null", alist.get(25));
    assertTrue("Should have returned the old item from slot 25", alist.get(26) == oldItem);

    alist.add(0, o = new Object());
    assertEquals("Failed to add Object", alist.get(0), o);
    assertEquals(alist.get(1), objArray[0]);
    assertEquals(alist.get(2), objArray[1]);

    oldItem = alist.get(0);
    alist.add(0, null);
    assertNull("Should have returned null", alist.get(0));
    assertEquals("Should have returned the old item from slot 0", alist.get(1), oldItem);

    try {
      alist.add(-1, new Object());
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      alist.add(-1, null);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      alist.add(alist.size() + 1, new Object());
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      alist.add(alist.size() + 1, null);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }
  }
コード例 #2
0
  /** @tests {@link java.util.ArrayList#removeRange(int, int)} */
  public void test_removeRange() {
    MockArrayList mylist = new MockArrayList();
    mylist.removeRange(0, 0);

    try {
      mylist.removeRange(0, 1);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    int[] data = {1, 2, 3};
    for (int i = 0; i < data.length; i++) {
      mylist.add(i, data[i]);
    }

    mylist.removeRange(0, 1);
    assertEquals(data[1], mylist.get(0));
    assertEquals(data[2], mylist.get(1));

    try {
      mylist.removeRange(-1, 1);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      mylist.removeRange(0, -1);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      mylist.removeRange(1, 0);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      mylist.removeRange(2, 1);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }
  }
コード例 #3
0
  public int insertRule(final String rule, final int index) throws DOMException {
    final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl();
    if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) {
      throw new DOMExceptionImpl(
          DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET);
    }

    try {
      final InputSource is = new InputSource(new StringReader(rule));
      final CSSOMParser parser = new CSSOMParser();
      parser.setParentStyleSheet(parentStyleSheet);
      parser.setErrorHandler(ThrowCssExceptionErrorHandler.INSTANCE);
      // parser._parentRule is never read
      // parser.setParentRule(_parentRule);
      final CSSRule r = parser.parseRule(is);

      // Insert the rule into the list of rules
      ((CSSRuleListImpl) getCssRules()).insert(r, index);

    } catch (final IndexOutOfBoundsException e) {
      throw new DOMExceptionImpl(
          DOMException.INDEX_SIZE_ERR, DOMExceptionImpl.INDEX_OUT_OF_BOUNDS, e.getMessage());
    } catch (final CSSException e) {
      throw new DOMExceptionImpl(
          DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
    } catch (final IOException e) {
      throw new DOMExceptionImpl(
          DOMException.SYNTAX_ERR, DOMExceptionImpl.SYNTAX_ERROR, e.getMessage());
    }
    return index;
  }
コード例 #4
0
 private static int getJpegSize(ByteBuffer data) {
   if (data.get(0) != (byte) 0xff || data.get(1) != (byte) 0xd8)
     throw new VisionException("invalid image");
   int pos = 2;
   while (true) {
     try {
       byte b = data.get(pos);
       if (b != (byte) 0xff)
         throw new VisionException("invalid image at pos " + pos + " (" + data.get(pos) + ")");
       b = data.get(pos + 1);
       if (b == (byte) 0x01 || (b >= (byte) 0xd0 && b <= (byte) 0xd7)) // various
       pos += 2;
       else if (b == (byte) 0xd9) // EOI
       return pos + 2;
       else if (b == (byte) 0xd8) // SOI
       throw new VisionException("invalid image");
       else if (b == (byte) 0xda) { // SOS
         int len = ((data.get(pos + 2) & 0xff) << 8) | (data.get(pos + 3) & 0xff);
         pos += len + 2;
         // Find next marker. Skip over escaped and RST markers.
         while (data.get(pos) != (byte) 0xff
             || data.get(pos + 1) == (byte) 0x00
             || (data.get(pos + 1) >= (byte) 0xd0 && data.get(pos + 1) <= (byte) 0xd7)) pos += 1;
       } else { // various
         int len = ((data.get(pos + 2) & 0xff) << 8) | (data.get(pos + 3) & 0xff);
         pos += len + 2;
       }
     } catch (IndexOutOfBoundsException ex) {
       throw new VisionException("invalid image: could not find jpeg end " + ex.getMessage());
     }
   }
 }
コード例 #5
0
ファイル: Itinerary.java プロジェクト: hchen96/hackerrank
  /**
   * Constructs a new itinerary object with origin and destination based on flights within it.
   *
   * @param flights The list of the itineray's flights
   */
  public Itinerary(ArrayList<Flight> flights) {
    try {
      // Create new calander for departure date time for easy calculation
      // of time between arrival and departure dates.
      GregorianCalendar temp = flights.get(0).getDepartureDateTime();
      this.departureDate =
          new GregorianCalendar(
              temp.get(Calendar.YEAR), temp.get(Calendar.MONTH), temp.get(Calendar.DATE));
      this.origin = flights.get(0).getOrigin();
      this.destination = flights.get(flights.size() - 1).getDestination();
      this.flights = flights;
      this.departureDateAsStr = flights.get(0).getDepartureDateTimeAsStr().split(" ")[0];

      // cycle through all flights and get total cots and total
      // travel time without wait time
      for (Flight f : this.flights) {
        this.totalCost += f.getCost();
        this.totalTravelTime += f.calculateTravelTime();
      }

      // Calculate wait time between flights as a list of int in minutes.
      this.calculateWaitTime();
    } catch (IndexOutOfBoundsException e) {
      System.out.println("Empty list of flights given " + e.getMessage());
    }
  }
コード例 #6
0
 public Chapter createChapter(int id, String page) {
   Chapter chapter = new Chapter(id);
   chapter.setUrl(Constants.BASE_URL + getVersion() + page);
   String cache = getCachePath() + page;
   try {
     String html = client.requestWithCache(chapter.getUrl(), cache, client.METHOD_GET, null);
     Document chapterDoc = Jsoup.parse(html);
     // 取出内容
     Elements tables = chapterDoc.select("table");
     int tableIndexOfMainBody = 1;
     if (tables.size() == 1) {
       tableIndexOfMainBody = 0;
     }
     Element table = chapterDoc.select("table").get(tableIndexOfMainBody);
     Elements sectionElements = table.select("td[class=v]");
     logger.debug(sectionElements.size());
     for (Element tdIndex : sectionElements) {
       Element tdContent = tdIndex.nextElementSibling();
       String section = tdContent.text();
       logger.debug(section);
       chapter.addSection(section);
     }
   } catch (IOException e) {
     logger.error(e.getMessage());
   } catch (IndexOutOfBoundsException e) {
     logger.error(e.getMessage());
   }
   return chapter;
 }
コード例 #7
0
ファイル: ExoUtils.java プロジェクト: omusico/mobile-android
 /**
  * Extract a name from a Server URL by keeping the 1st part of the FQDN, between the protocol and
  * the first dot or the end of the URL. It is then capitalized. If an IP address is given instead,
  * it is used as-is. Examples:
  *
  * <ul>
  *   <li>http://int.exoplatform.com => Int
  *   <li>http://community.exoplatform.com => Community
  *   <li>https://mycompany.com => Mycompany
  *   <li>https://intranet.secure.mycompany.co.uk => Intranet
  *   <li>http://localhost => Localhost
  *   <li>http://192.168.1.15 => 192.168.1.15
  * </ul>
  *
  * @param url the Server URL
  * @param defaultName a default name in case it is impossible to extract
  * @return a name
  */
 public static String getAccountNameFromURL(String url, String defaultName) {
   String finalName = defaultName;
   if (url != null && !url.isEmpty()) {
     if (!url.startsWith("http")) url = ExoConnectionUtils.HTTP + url;
     try {
       URI theURL = new URI(url);
       finalName = theURL.getHost();
       if (!isCorrectIPAddress(finalName)) {
         int firstDot = finalName.indexOf('.');
         if (firstDot > 0) {
           finalName = finalName.substring(0, firstDot);
         }
         // else, no dot was found in the host,
         // return the hostname as is, e.g. localhost
       }
       // else, URL is an IP address, return it as is
     } catch (URISyntaxException e) {
       if (Log.LOGD)
         Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e));
       finalName = defaultName;
     } catch (IndexOutOfBoundsException e) {
       if (Log.LOGD)
         Log.d(ExoUtils.class.getSimpleName(), e.getMessage(), Log.getStackTraceString(e));
       finalName = defaultName;
     }
   }
   return capitalize(finalName);
 }
コード例 #8
0
  /** @tests java.util.ArrayList#remove(int) */
  public void test_removeI() {
    // Test for method java.lang.Object java.util.ArrayList.remove(int)
    alist.remove(10);
    assertEquals("Failed to remove element", -1, alist.indexOf(objArray[10]));
    try {
      alist.remove(999);
      fail("Failed to throw exception when index out of range");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    ArrayList myList = (ArrayList) (((ArrayList) (alist)).clone());
    alist.add(25, null);
    alist.add(50, null);
    alist.remove(50);
    alist.remove(25);
    assertTrue("Removing nulls did not work", alist.equals(myList));

    List list = new ArrayList(Arrays.asList(new String[] {"a", "b", "c", "d", "e", "f", "g"}));
    assertTrue("Removed wrong element 1", list.remove(0) == "a");
    assertTrue("Removed wrong element 2", list.remove(4) == "f");
    String[] result = new String[5];
    list.toArray(result);
    assertTrue(
        "Removed wrong element 3", Arrays.equals(result, new String[] {"b", "c", "d", "e", "g"}));

    List l = new ArrayList(0);
    l.add(new Object());
    l.add(new Object());
    l.remove(0);
    l.remove(0);
    try {
      l.remove(-1);
      fail("-1 should cause exception");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }
    try {
      l.remove(0);
      fail("0 should case exception");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }
  }
コード例 #9
0
  /** @tests java.util.ArrayList#set(int, java.lang.Object) */
  public void test_setILjava_lang_Object() {
    // Test for method java.lang.Object java.util.ArrayList.set(int,
    // java.lang.Object)
    Object obj;
    alist.set(65, obj = new Object());
    assertTrue("Failed to set object", alist.get(65) == obj);
    alist.set(50, null);
    assertNull("Setting to null did not work", alist.get(50));
    assertTrue("Setting increased the list's size to: " + alist.size(), alist.size() == 100);

    obj = new Object();
    alist.set(0, obj);
    assertTrue("Failed to set object", alist.get(0) == obj);

    try {
      alist.set(-1, obj);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      alist.set(alist.size(), obj);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      alist.set(-1, null);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      alist.set(alist.size(), null);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }
  }
コード例 #10
0
  public static String idToClass(String repid) {
    // debug
    logger.finer("idToClass " + repid);

    if (repid.startsWith("IDL:")) {

      ByteString id = new ByteString(repid);

      try {
        int end = id.lastIndexOf(':');
        ByteString s = end < 0 ? id.substring(4) : id.substring(4, end);

        ByteBuffer bb = new ByteBuffer();

        //
        // reverse order of dot-separated name components up
        // till the first slash.
        //
        int firstSlash = s.indexOf('/');
        if (firstSlash > 0) {
          ByteString prefix = s.substring(0, firstSlash);
          ByteString[] elems = prefix.split('.');

          for (int i = elems.length - 1; i >= 0; i--) {
            bb.append(fixName(elems[i]));
            bb.append('.');
          }

          s = s.substring(firstSlash + 1);
        }

        //
        // Append slash-separated name components ...
        //
        ByteString[] elems = s.split('/');
        for (int i = 0; i < elems.length; i++) {
          bb.append(fixName(elems[i]));
          if (i != elems.length - 1) bb.append('.');
        }

        String result = bb.toString();

        logger.finer("idToClassName " + repid + " => " + result);

        return result;
      } catch (IndexOutOfBoundsException ex) {
        logger.log(Level.FINE, "idToClass " + ex.getMessage(), ex);
        return null;
      }

    } else if (repid.startsWith("RMI:")) {
      int end = repid.indexOf(':', 4);
      return end < 0 ? repid.substring(4) : repid.substring(4, end);
    }

    return null;
  }
コード例 #11
0
ファイル: Track.java プロジェクト: nmldiegues/jamify
 /**
  * Obtains the event at the specified index.
  *
  * @param index the location of the desired event in the event vector
  * @throws <code>ArrayIndexOutOfBoundsException</code> if the specified index is negative or not
  *     less than the current size of this track.
  * @see #size
  */
 public MidiEvent get(int index) throws ArrayIndexOutOfBoundsException {
   try {
     synchronized (eventsList) {
       return (MidiEvent) eventsList.get(index);
     }
   } catch (IndexOutOfBoundsException ioobe) {
     throw new ArrayIndexOutOfBoundsException(ioobe.getMessage());
   }
 }
コード例 #12
0
 @Test
 public void should_fail_if_index_is_out_of_bounds() {
   try {
     location.checkIndexInBounds(tabbedPane, 2);
     failWhenExpectingException();
   } catch (IndexOutOfBoundsException e) {
     assertThat(e.getMessage())
         .isEqualTo("Index <2> is not within the JTabbedPane bounds of <0> and <1> (inclusive)");
   }
 }
コード例 #13
0
ファイル: NioByteString.java プロジェクト: JingchengDu/hbase
 @Override
 public byte byteAt(int index) {
   try {
     return buffer.get(index);
   } catch (ArrayIndexOutOfBoundsException e) {
     throw e;
   } catch (IndexOutOfBoundsException e) {
     throw new ArrayIndexOutOfBoundsException(e.getMessage());
   }
 }
コード例 #14
0
  /** @tests java.util.ArrayList#addAll(int, java.util.Collection) */
  public void test_addAllILjava_util_Collection_3() {
    ArrayList obj = new ArrayList();
    obj.addAll(0, obj);
    obj.addAll(obj.size(), obj);
    try {
      obj.addAll(-1, obj);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      obj.addAll(obj.size() + 1, obj);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      obj.addAll(0, null);
      fail("Should throw NullPointerException");
    } catch (NullPointerException e) {
      // Excepted
    }

    try {
      obj.addAll(obj.size() + 1, null);
      fail("Should throw IndexOutOfBoundsException");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }

    try {
      obj.addAll((int) -1, (Collection) null);
      fail("IndexOutOfBoundsException expected");
    } catch (IndexOutOfBoundsException e) {
      // Expected
      assertNotNull(e.getMessage());
    }
  }
コード例 #15
0
 /** @tests java.util.ArrayList#get(int) */
 public void test_getI() {
   // Test for method java.lang.Object java.util.ArrayList.get(int)
   assertTrue("Returned incorrect element", alist.get(22) == objArray[22]);
   try {
     alist.get(8765);
     fail("Failed to throw expected exception for index > size");
   } catch (IndexOutOfBoundsException e) {
     // Expected
     assertNotNull(e.getMessage());
   }
 }
コード例 #16
0
ファイル: NioByteString.java プロジェクト: JingchengDu/hbase
 @Override
 public ByteString substring(int beginIndex, int endIndex) {
   try {
     ByteBuffer slice = slice(beginIndex, endIndex);
     return new NioByteString(slice);
   } catch (ArrayIndexOutOfBoundsException e) {
     throw e;
   } catch (IndexOutOfBoundsException e) {
     throw new ArrayIndexOutOfBoundsException(e.getMessage());
   }
 }
コード例 #17
0
 public void set(int paramInt1, int paramInt2) {
   try {
     setSpan(getBss(), paramInt1, paramInt2, 18);
     setSpan(getFss(), paramInt1, paramInt2, 18);
     return;
   } catch (IndexOutOfBoundsException localIndexOutOfBoundsException) {
     CrDb.d(
         "fragment link trie malfunctioning",
         localIndexOutOfBoundsException.getMessage() + " @ " + this.text);
   }
 }
コード例 #18
0
 private Object evaluateJsonPath(String content) throws ParseException {
   String message = "No value for JSON path: " + this.expression + ", exception: ";
   try {
     return this.jsonPath.read(content);
   } catch (InvalidPathException ex) {
     throw new AssertionError(message + ex.getMessage());
   } catch (ArrayIndexOutOfBoundsException ex) {
     throw new AssertionError(message + ex.getMessage());
   } catch (IndexOutOfBoundsException ex) {
     throw new AssertionError(message + ex.getMessage());
   }
 }
コード例 #19
0
ファイル: List.java プロジェクト: eGit/appengine-awt
 public void replaceItem(String newValue, int index) {
   toolkit.lockAWT();
   try {
     items.set(index, newValue);
     updatePrefWidth();
     doRepaint();
   } catch (IndexOutOfBoundsException e) {
     throw new ArrayIndexOutOfBoundsException(e.getMessage());
   } finally {
     toolkit.unlockAWT();
   }
 }
コード例 #20
0
 public void deleteRule(final int index) throws DOMException {
   final CSSStyleSheetImpl parentStyleSheet = getParentStyleSheetImpl();
   if (parentStyleSheet != null && parentStyleSheet.isReadOnly()) {
     throw new DOMExceptionImpl(
         DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMExceptionImpl.READ_ONLY_STYLE_SHEET);
   }
   try {
     ((CSSRuleListImpl) getCssRules()).delete(index);
   } catch (final IndexOutOfBoundsException e) {
     throw new DOMExceptionImpl(
         DOMException.INDEX_SIZE_ERR, DOMExceptionImpl.INDEX_OUT_OF_BOUNDS, e.getMessage());
   }
 }
コード例 #21
0
  /**
   * Copies the contents of the <code>TextField</code> into a character array starting at index
   * zero. Array elements beyond the characters copied are left unchanged.
   *
   * @param data the character array to receive the value
   * @return the number of characters copied
   * @throws ArrayIndexOutOfBoundsException if the array is too short for the contents
   * @throws NullPointerException if <code>data</code> is <code>null</code>
   * @see #setChars
   */
  public int getChars(char[] data) {

    synchronized (Display.LCDUILock) {
      textFieldLF.lUpdateContents();

      try {
        buffer.getChars(0, buffer.length(), data, 0);
      } catch (IndexOutOfBoundsException e) {
        throw new ArrayIndexOutOfBoundsException(e.getMessage());
      }

      return buffer.length();
    }
  }
コード例 #22
0
ファイル: Parser.java プロジェクト: ditho/WPSR
 /**
  * Get the value for in the given String. This method handles more then one escape character.
  *
  * @param str to parse the value
  * @param index begin of the value
  * @param esc end of the value
  * @return the value of the searched key
  */
 public static String parseValue(String str, int index, String esc) {
   String value = "";
   try {
     // while the index is not out of bound positively
     // and the character is not an escape one.
     while (index < str.length() && !esc.contains(String.valueOf(str.charAt(index)))) {
       // expand value with the next character and increase the index
       value += str.charAt(index++);
     }
   } catch (final IndexOutOfBoundsException e) {
     logger.error(
         "[msg=" + e.getMessage() + ",str=" + str + ",index=" + index + ",esc=" + esc + "]", e);
   }
   logger.debug(value + esc);
   return value;
 }
コード例 #23
0
ファイル: OneTwo.java プロジェクト: scott-walker/My-Stuff
  public static void main(String[] args) {
    int[] whee = new int[5];

    try {
      Blah testBlah = new Blah();
      testBlah.xxx().toString();
    } catch (NullPointerException e) {
      System.out.println("NullPointerException message: " + e.getMessage());
      e.printStackTrace();
      System.out.println("------------------------");
      System.out.println();
    }

    try {
      int[] whee2 = new int[-2];
    } catch (NegativeArraySizeException e) {
      System.out.println("NegativeArraySizeException message: " + e.getMessage());
      e.printStackTrace();
      System.out.println("------------------------");
      System.out.println();
    }

    try {
      whee[9] = 3;
    } catch (IndexOutOfBoundsException e) {
      System.out.println("IndexOutOfBoundsException message: " + e.getMessage());
      e.printStackTrace();
      System.out.println("------------------------");
      System.out.println();
    }

    try {
      divide(whee, 10);
    } catch (MyException e) {
      System.out.println("Custom message: " + e.getMessage());
    }

    try {
      divide(whee, -2);
    } catch (MyException e) {
      System.out.println("Custom message: " + e.getMessage());
    }
  }
コード例 #24
0
        public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) {
          // Cancel discovery because it's costly and we're about to connect
          mBtAdapter.cancelDiscovery();

          // Get the device MAC address, which is the last 17 chars in the
          // View
          String info = ((TextView) v).getText().toString();
          int index = info.length() - 17;
          String address = "";
          try {
            address = info.substring(index);
          } catch (IndexOutOfBoundsException e) {
            Log.e(TAG, e.getMessage());
            e.printStackTrace();
            return;
          }

          setAndReturn(address);
        }
コード例 #25
0
  public void writeList() {
    PrintWriter out = null;

    try {
      System.out.println("Entering try statement");
      out = new PrintWriter(new FileWriter("OutFile.txt"));

      for (int i = 0; i < SIZE; i++) out.println("Value at: " + i + " = " + list.get(i));
    } catch (IndexOutOfBoundsException e) {
      System.err.println("Caught IndexOutOfBoundsException: " + e.getMessage());
    } catch (IOException e) {
      System.err.println("Caught IOException: " + e.getMessage());
    } finally {
      if (out != null) {
        System.out.println("Closing PrintWriter");
        out.close();
      } else {
        System.out.println("PrintWriter not open");
      }
    }
  }
コード例 #26
0
  /**
   * Checks if the suffix added in the memory version to all requests in the HDIV parameter is the
   * same as the one stored in session, which is the original suffix. So any request using the
   * memory version should keep the suffix unchanged.
   *
   * @param value value received in the HDIV parameter
   * @return True if the received value of the suffix is valid. False otherwise.
   */
  public boolean validateHDIVSuffix(String value) {

    int firstSeparator = value.indexOf("-");
    int lastSeparator = value.lastIndexOf("-");

    if (firstSeparator == -1) {

      return false;
    }

    if (firstSeparator >= lastSeparator) {

      return false;
    }

    try {
      // read hdiv's suffix from request
      String requestSuffix = value.substring(lastSeparator + 1);

      // read suffix from page stored in session
      String pageId = value.substring(0, firstSeparator);
      IPage currentPage = this.session.getPage(pageId);

      if (currentPage == null) {
        if (log.isErrorEnabled()) {
          log.error("Page with id [" + pageId + "] not found in session.");
        }
        throw new HDIVException(HDIVErrorCodes.PAGE_ID_INCORRECT);
      }

      return currentPage.getRandomToken().equals(requestSuffix);

    } catch (IndexOutOfBoundsException e) {
      String errorMessage = HDIVUtil.getMessage("validation.error", e.getMessage());
      if (log.isErrorEnabled()) {
        log.error(errorMessage);
      }
      throw new HDIVException(errorMessage, e);
    }
  }
コード例 #27
0
  public Object nextElement() throws NoSuchElementException {
    try {
      int next = next();

      String s = buffer.toString().substring(start, next);
      buffer.delete(0, next);

      position = start = 0;

      if (buffer.length() > 0) {
        if (buffer.charAt(0) == ' ' || buffer.charAt(0) == '\n') {
          buffer.deleteCharAt(0);
        }
      }

      return s.trim();
    } catch (IndexOutOfBoundsException e) {
      throw new NoSuchElementException(e.getMessage());
    } catch (Exception e) {
      throw new NoSuchElementException(e.getMessage());
    }
  }
コード例 #28
0
ファイル: TextViewHybrid.java プロジェクト: zukov/Jpicedt
  protected void getDimensionsFromLogFile(BufferedReader reader, PicText text) {
    if (reader == null) {
      return;
    }
    String line = ""; // il rale si j'initialise pas ...
    boolean finished = false;
    while (!finished) {
      try {
        line = reader.readLine();
      } catch (IOException ioex) {
        ioex.printStackTrace();
        return;
      }
      if (line == null) {
        System.out.println("Size of text not found in log file...");
        return;
      }

      System.out.println(line);
      Matcher matcher = LogFilePattern.matcher(line);

      if (line != null && matcher.find()) {
        System.out.println("FOUND :" + line);
        finished = true;
        try {
          text.setDimensions(
              0.3515 * Double.parseDouble(matcher.group(1)), // height, pt->mm (1pt=0.3515 mm)
              0.3515 * Double.parseDouble(matcher.group(2)), // width
              0.3515 * Double.parseDouble(matcher.group(3))); // depth
          areDimensionsComputed = true;
        } catch (NumberFormatException e) {
          System.out.println("Logfile number format problem: $line" + e.getMessage());
        } catch (IndexOutOfBoundsException e) {
          System.out.println("Logfile regexp problem: $line" + e.getMessage());
        }
      }
    }
    return;
  }
コード例 #29
0
ファイル: List.java プロジェクト: eGit/appengine-awt
 public void remove(int position) {
   toolkit.lockAWT();
   try {
     selection.remove(new Integer(position));
     items.remove(position);
     // decrease all selected indices greater than position
     // by 1, because items list is shifted to the left
     for (int i = 0; i < selection.size(); i++) {
       Integer idx = selection.get(i);
       int val = idx.intValue();
       if (val > position) {
         selection.set(i, new Integer(val - 1));
       }
     }
     updatePrefWidth();
     doRepaint();
   } catch (IndexOutOfBoundsException e) {
     throw new ArrayIndexOutOfBoundsException(e.getMessage());
   } finally {
     toolkit.unlockAWT();
   }
 }
コード例 #30
0
ファイル: zzfp.java プロジェクト: gdkjrygh/CompSecurity
    public void zzcX()
    {
        HttpURLConnection httpurlconnection;
        zzb.zzam((new StringBuilder()).append("Pinging URL: ").append(zzAX).toString());
        httpurlconnection = (HttpURLConnection)(new URL(zzAX)).openConnection();
        if (!TextUtils.isEmpty(zzBW))
        {
            break MISSING_BLOCK_LABEL_127;
        }
        zzh.zzaQ().zza(mContext, zzoc, true, httpurlconnection);
_L1:
        int i = httpurlconnection.getResponseCode();
        if (i >= 200 && i < 300)
        {
            break MISSING_BLOCK_LABEL_122;
        }
        zzb.zzan((new StringBuilder()).append("Received non-success response code ").append(i).append(" from pinging URL: ").append(zzAX).toString());
        Exception exception;
        try
        {
            httpurlconnection.disconnect();
            return;
        }
        catch (IndexOutOfBoundsException indexoutofboundsexception)
        {
            zzb.zzan((new StringBuilder()).append("Error while parsing ping URL: ").append(zzAX).append(". ").append(indexoutofboundsexception.getMessage()).toString());
            return;
        }
        catch (IOException ioexception)
        {
            zzb.zzan((new StringBuilder()).append("Error while pinging URL: ").append(zzAX).append(". ").append(ioexception.getMessage()).toString());
            return;
        }
        catch (RuntimeException runtimeexception)
        {
            zzb.zzan((new StringBuilder()).append("Error while pinging URL: ").append(zzAX).append(". ").append(runtimeexception.getMessage()).toString());
        }
        break MISSING_BLOCK_LABEL_273;
        zzh.zzaQ().zza(mContext, zzoc, true, httpurlconnection, zzBW);
          goto _L1