Exemplo n.º 1
0
 /**
  * Test of doOCR method, of class Tesseract.
  *
  * @throws Exception while processing image.
  */
 @Test
 public void testDoOCR_List_Rectangle() throws Exception {
   File imageFile = null;
   String expResult = "The (quick) [brown] {fox} jumps!\nOver the $43,456.78 <lazy> #90 dog";
   String result = "<empty>";
   try {
     logger.info("doOCR on a PDF document");
     imageFile = new File(this.testResourcesDataPath, "eurotext.pdf");
     List<IIOImage> imageList = ImageIOHelper.getIIOImageList(imageFile);
     result = instance.doOCR(imageList, null);
     logger.info(result);
     assertEquals(expResult, result.substring(0, expResult.length()));
   } catch (IOException e) {
     logger.error(
         "Exception-Message: '{}'. Imagefile: '{}'",
         e.getMessage(),
         imageFile.getAbsoluteFile(),
         e);
     fail();
   } catch (TesseractException e) {
     logger.error(
         "Exception-Message: '{}'. Imagefile: '{}'",
         e.getMessage(),
         imageFile.getAbsoluteFile(),
         e);
     fail();
   } catch (StringIndexOutOfBoundsException e) {
     logger.error(
         "Exception-Message: '{}'. Imagefile: '{}'",
         e.getMessage(),
         imageFile.getAbsoluteFile(),
         e);
     fail();
   }
 }
Exemplo n.º 2
0
 /** @tests java.lang.String#substring(int, int) */
 public void test_substringErrorMessage() {
   try {
     hw1.substring(-1, 1);
   } catch (StringIndexOutOfBoundsException ex) {
     String msg = ex.getMessage();
     assertTrue("Expected message to contain -1: " + msg, msg.indexOf("-1") != -1);
   }
   try {
     hw1.substring(4, 1);
   } catch (StringIndexOutOfBoundsException ex) {
     String msg = ex.getMessage();
     assertTrue("Expected message to contain -3: " + msg, msg.indexOf("-3") != -1);
   }
   try {
     hw1.substring(0, 100);
   } catch (StringIndexOutOfBoundsException ex) {
     String msg = ex.getMessage();
     assertTrue("Expected message to contain 100: " + msg, msg.indexOf("100") != -1);
   }
 }
Exemplo n.º 3
0
 @Test
 public void testGetThrowsStringIndexOutOfBoundsException() throws Throwable {
   FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath");
   try {
     fSDMsg.get("testFSDMsgId", "", 100, "testFSDMsgDefValue", null);
     fail("Expected StringIndexOutOfBoundsException to be thrown");
   } catch (StringIndexOutOfBoundsException ex) {
     assertEquals("ex.getMessage()", "String index out of range: 0", ex.getMessage());
     assertEquals("fSDMsg.fields.size()", 0, fSDMsg.fields.size());
   }
 }
Exemplo n.º 4
0
 @Test
 public void testGetHexHeaderThrowsStringIndexOutOfBoundsException() throws Throwable {
   FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema");
   byte[] h = new byte[0];
   fSDMsg.setHeader(h);
   try {
     fSDMsg.getHexHeader();
     fail("Expected StringIndexOutOfBoundsException to be thrown");
   } catch (StringIndexOutOfBoundsException ex) {
     assertEquals("ex.getMessage()", "String index out of range: -2", ex.getMessage());
   }
 }
Exemplo n.º 5
0
 @Test
 public void testDumpThrowsStringIndexOutOfBoundsException() throws Throwable {
   byte[] h = new byte[0];
   FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema");
   fSDMsg.setHeader(h);
   PrintStream p = new PrintStream(new ByteArrayOutputStream(), true, "UTF-16");
   try {
     fSDMsg.dump(p, "testFSDMsgIndent");
     fail("Expected StringIndexOutOfBoundsException to be thrown");
   } catch (StringIndexOutOfBoundsException ex) {
     assertEquals("ex.getMessage()", "String index out of range: -2", ex.getMessage());
     assertEquals("fSDMsg.fields.size()", 0, fSDMsg.fields.size());
   }
 }
  public String urlStringToKey(final String urlString) throws URIException {

    if (urlString.startsWith("dns:")) {
      return urlString;
    }
    String searchUrl = canonicalize(urlString);
    String scheme = UrlOperations.urlToScheme(searchUrl);
    if (scheme != null) {
      searchUrl = searchUrl.substring(scheme.length());
    } else {
      scheme = UrlOperations.HTTP_SCHEME;
    }

    if (-1 == searchUrl.indexOf("/")) {
      searchUrl = scheme + searchUrl + "/";
    } else {
      searchUrl = scheme + searchUrl;
    }

    // Custom rules

    for (CanonicalizationRule rule : getProcessingRules()) {
      searchUrl = rule.processIfMatches(new CanonicalizationInput(searchUrl));
    }

    // Core rules

    // TODO: These next few lines look crazy -- need to be reworked.. This
    // was the only easy way I could find to get the correct unescaping
    // out of UsableURIs, possible a bug. Definitely needs some TLC in any case,
    // as building UsableURIs is *not* a cheap operation.

    // unescape anything that can be:
    UsableURI tmpURI = null;
    try {
      tmpURI = UsableURIFactory.getInstance(searchUrl);
    } catch (StringIndexOutOfBoundsException e) {
      LOGGER.warning(e.getMessage() + ": " + searchUrl);
      return searchUrl;
      //		} catch(URIException e) {
      //			LOGGER.warning(e.getMessage() + ": " + searchUrl);
      //			return searchUrl;
    }
    tmpURI.setPath(tmpURI.getPath());

    // convert to UsableURI to perform required URI fixup:
    UsableURI searchURI = UsableURIFactory.getInstance(tmpURI.getURI());

    // replace ' ' with '+' (this is only to match Alexa's canonicalization)
    String newPath = searchURI.getEscapedPath().replace("%20", "+");

    // replace multiple consecutive '/'s in the path.
    while (newPath.contains("//")) {
      newPath = newPath.replace("//", "/");
    }

    // this would remove trailing a '/' character, unless the path is empty
    // but we're not going to do this just yet..
    //		if((newPath.length() > 1) && newPath.endsWith("/")) {
    //			newPath = newPath.substring(0,newPath.length()-1);
    //		}

    StringBuilder sb = new StringBuilder(searchUrl.length());
    sb.append(searchURI.getHostBasename());

    // omit port if scheme default:
    int defaultSchemePort = UrlOperations.schemeToDefaultPort(scheme);
    if (searchURI.getPort() != defaultSchemePort && searchURI.getPort() != -1) {

      sb.append(":").append(searchURI.getPort());
    }

    sb.append(newPath);
    if (searchURI.getEscapedQuery() != null) {
      sb.append("?").append(searchURI.getEscapedQuery());
    }

    return sb.toString();
  }
Exemplo n.º 7
0
  private void loadobject(BufferedReader br, String pathtoimages) {
    int linecounter = 0;
    try {

      String newline;
      boolean firstpass = true;
      mtl matset = new mtl();
      int mtlcounter = 0;

      while (((newline = br.readLine()) != null)) {
        linecounter++;
        newline = newline.trim();
        if (newline.length() > 0) {
          if (newline.charAt(0) == 'n' && newline.charAt(1) == 'e' && newline.charAt(2) == 'w') {
            if (firstpass) {
              firstpass = false;
            } else {
              Materials.add(matset);
              matset = new mtl();
            }
            String[] coordstext = new String[2];
            coordstext = newline.split("\\s+");
            matset.name = coordstext[1];
            matset.mtlnum = mtlcounter;
            mtlcounter++;
          } else if (newline.charAt(0) == 'K' && newline.charAt(1) == 'a') {
            float[] coords = new float[3];
            String[] coordstext = new String[4];
            coordstext = newline.split("\\s+");
            for (int i = 1; i < coordstext.length; i++) {
              coords[i - 1] = Float.valueOf(coordstext[i]).floatValue();
            }
            matset.Ka = coords;
          } else if (newline.charAt(0) == 'K' && newline.charAt(1) == 'd') {
            float[] coords = new float[3];
            String[] coordstext = new String[4];
            coordstext = newline.split("\\s+");
            for (int i = 1; i < coordstext.length; i++) {
              coords[i - 1] = Float.valueOf(coordstext[i]).floatValue();
            }
            matset.Kd = coords;
          } else if (newline.charAt(0) == 'K' && newline.charAt(1) == 's') {
            float[] coords = new float[3];
            String[] coordstext = new String[4];
            coordstext = newline.split("\\s+");
            for (int i = 1; i < coordstext.length; i++) {
              coords[i - 1] = Float.valueOf(coordstext[i]).floatValue();
            }
            matset.Ks = coords;
          } else if (newline.charAt(0) == 'd') {
            String[] coordstext = newline.split("\\s+");
            matset.d = Float.valueOf(coordstext[1]).floatValue();
          } else if (newline.contains("map_Ka")) {
            String texture = newline.replace("map_Ka ", "");
            while (texture.startsWith(" ")) texture = texture.replaceFirst(" ", "");
            if (texture != null) matset.map_Ka = texture;
          } else if (newline.contains("map_Kd")) {
            String texture = newline.replace("map_Kd ", "");
            while (texture.startsWith(" ")) texture = texture.replaceFirst(" ", "");
            if (texture != null) matset.map_Kd = texture;
          } else if (newline.contains("map_d")) {
            String texture = newline.replace("map_d ", "");
            while (texture.startsWith(" ")) texture = texture.replaceFirst(" ", "");
            if (texture != null) matset.map_d = texture;
          }
        }
      }
      Materials.add(matset);

    } catch (IOException e) {
      System.out.println("Failed to read file: " + br.toString());
      e.printStackTrace();
    } catch (NumberFormatException e) {
      System.out.println(
          "Malformed MTL (on line "
              + linecounter
              + "): "
              + br.toString()
              + "\r \r"
              + e.getMessage());
    } catch (StringIndexOutOfBoundsException e) {
      System.out.println(
          "Malformed MTL (on line "
              + linecounter
              + "): "
              + br.toString()
              + "\r \r"
              + e.getMessage());
    }
  }
Exemplo n.º 8
0
 /**
  * This is the method which will upload the properties file into Cache and will bind cache to
  * POJO. This method will share a lock and condition object with ReturnMapValue method to avoid
  * concurrent access to HashMap. Following precautions has been taken to avoid concurrent HashMap
  * access problem: ConcurrentHashMap has been choosen. UnmodifiableHashMap has been returned to
  * caller so that other party doesn't modify it.
  */
 void loadPropertiesFile()
     throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
   this.priorityFlag = true;
   updateLock.lock();
   logger.debug("UPDATE HAS THE LOCK");
   try {
     logger.debug("Loading the properties file");
     for (FolderEvent event : eventQueue) {
       logger.debug("Event size " + eventQueue.size());
       switch (event) {
         case LOAD:
           {
             for (String name : load) {
               try {
                 String className = name.substring(0, name.indexOf(".")).concat("Handler");
                 PropHandler handler = null;
                 if (propMap.get(name) == null) {
                   // ----MEANS This is the first time.
                   try {
                     handler =
                         (PropHandler) Class.forName("com.GR.handler." + className).newInstance();
                     handler.loadPropertiesFile(location + File.separator + name);
                     handler.initialize();
                     handler.addToSession(propMap);
                     beanPropHandlerMap.put(propMap.get(name), handler);
                   } catch (ClassNotFoundException e) {
                     logger.info(
                         "No Handler/Bean has been defined for the ["
                             + name
                             + "] properties file");
                     logger.error("IGNORE -->" + e.getMessage());
                   }
                 } else {
                   handler = beanPropHandlerMap.get(propMap.get(name));
                   handler.loadPropertiesFile(location + File.separator + name);
                   handler.initialize();
                   handler.addToSession(propMap);
                 }
               } catch (StringIndexOutOfBoundsException e) {
                 logger.info(name + " doesn't seem to be a valid property file name");
                 logger.error("IGNORE -->" + e.getMessage());
               }
             } // End of For Loop for Load Class
             break;
           }
         case UNLOAD:
           {
             for (String name : unload) {
               propMap.remove(name);
             }
             break;
           }
       }
     }
     // -------------------CLEAR THE QUEUES--------------
     eventQueue.clear();
     load.clear();
     unload.clear();
     isRefreshed = true;
   } finally {
     // -----------------NOTIFY the returnMapValue-----------
     this.priorityFlag = false;
     loadCondition.signal();
     updateLock.unlock();
     logger.info("Files uploaded into Cache");
     logger.debug("UPDATE RELEASED THE LOCK");
   }
 }
 protected String extractClassificationNameFromOption(boolean check) {
   if (_extracted) {
     return _specifiedValue;
   }
   _extracted = true;
   final String pmbMetaDataPropertyOption = getPmbMetaDataPropertyOption();
   if (pmbMetaDataPropertyOption == null) {
     if (check) {
       String msg = "The property name didn't have its option:";
       msg = msg + " " + _pmbMetaData.getClassName() + "." + _propertyName;
       throw new IllegalStateException(msg);
     } else {
       return null;
     }
   }
   String option = pmbMetaDataPropertyOption.trim();
   {
     if (option.trim().length() == 0) {
       if (check) {
         String msg = "The option of the property name should not be empty:";
         msg = msg + " property=" + _pmbMetaData.getClassName() + "." + _propertyName;
         throw new IllegalStateException(msg);
       } else {
         return null;
       }
     }
     final List<String> splitOption = splitOption(option);
     String firstOption = null;
     for (String element : splitOption) {
       if (element.startsWith(OPTION_PREFIX) && element.endsWith(OPTION_SUFFIX)) {
         firstOption = element;
         break;
       }
     }
     if (firstOption == null) {
       if (check) {
         String msg = "The option of class name and the property name should be 'cls(xxx)':";
         msg =
             msg + " property=" + _pmbMetaData.getClassName() + "." + _propertyName + ":" + option;
         throw new IllegalStateException(msg);
       } else {
         return null;
       }
     }
     option = firstOption;
   }
   final int clsIdx = OPTION_PREFIX.length();
   final int clsEndIdx = option.length() - OPTION_SUFFIX.length();
   try {
     _specifiedValue = option.substring(clsIdx, clsEndIdx);
   } catch (StringIndexOutOfBoundsException e) {
     final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
     br.addNotice("The classification option for the parameter comment was invalid.");
     br.addItem("ParameterBean");
     br.addElement(_pmbMetaData.getClassName());
     br.addItem("Property");
     br.addElement(_propertyName);
     br.addItem("Option");
     br.addElement(option);
     br.addItem("Exception");
     br.addElement(e.getClass());
     br.addElement(e.getMessage());
     br.addElement("{" + option + "}.substring(" + clsIdx + ", " + clsEndIdx + ")");
     final String msg = br.buildExceptionMessage();
     throw new IllegalStateException(msg, e);
   }
   return _specifiedValue;
 }