Load and create LinkSets and Link from persisted file

@throws Exception
180066
public void load() {

        try {
            File f = new File(persistFile.toString());
            if (f.exists()) {
                // we have V4 config
                loadVer4(persistFile.toString());
            } else {
                String s1 = persistFile.toString().replace("3.xml", "2.xml");
                f = new File(s1);

                if (f.exists()) {
                    loadVer3(s1);
                    this.store();
                    f.delete();
                } else {
                    s1 = persistFile.toString().replace("3.xml", ".xml");
                    f = new File(s1);

                    if (f.exists()) {
                        if (!loadVer1(s1)) {
                            loadVer2(s1);
                        }
                    }

                    this.store();
                    f.delete();
                }
            }

//            File f = new File(persistFile.toString());
//            if (f.exists()) {
//                // we have V3 config
//                loadVer3(persistFile.toString());
//            } else {
//                String s1 = persistFile.toString().replace("2.xml", ".xml");
//                f = new File(s1);
//
//                if (f.exists()) {
//                    if (!loadVer1(s1)) {
//                        loadVer2(s1);
//                    }
//                }
//
//                this.store();
//                f.delete();
//            }
        } catch (XMLStreamException ex) {
            ex.printStackTrace();
            logger.error(String.format("Failed to load the SS7 configuration file. \n%s", ex.getMessage()));
        } catch (FileNotFoundException e) {
            logger.warn(String.format("Failed to load the SS7 configuration file. \n%s", e.getMessage()));
        } catch (IOException e) {
            logger.error(String.format("Failed to load the SS7 configuration file. \n%s", e.getMessage()));
        }
    }
116430
public static function load() {
        $configFile = MODULES_DIR . DS . RouteController::$currentModule . '/Config/config.php';

        if (!file_exists($configFile)) {
            $configFile = BASE_DIR . '/config/config.php';
            if (!file_exists($configFile)) {
                throw new \Exception(ExceptionMessages::CONFIG_FILE_NOT_FOUND);
            }
        }

        if (empty(self::$configs)) {
            self::$configs = require_once $configFile;
        }
    }
1340133
public void init() throws ServletException {
        _application = ((ManagedPlatform)ServicePlatform.getService(ManagedPlatform.INSTANCE).first).getName();

/*
        ApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
        if (wac.containsBean("persistence")) { // persistence may not be there if persistent storage is not required
            _persistence = (Persistence)wac.getBean("persistence");
        }
*/
    }
169159
private function load()
    {
        $filename = $this->path . '/domainparsertld.txt';

        if (file_exists($filename)) {
            $this->tldList = unserialize(file_get_contents($filename));

            // will reload tld list if timestamp of cache file is outdated
            if (time() - $this->tldList['timestamp'] > $this->cacheTime) {
                $this->reload = true;
            }

            // will reload tld list if changes to Additional.php have been made
            if ($this->tldList['timestamp'] < filemtime(__DIR__ .'/Additional.php')) {
                $this->reload = true;
            }
        }

        // check connection - if there is no internet connection skip loading
        $existFile = file_exists($filename);

        if (! $existFile || $this->reload === true) {
            $this->catchTlds($existFile);
            $file = fopen($filename, 'w+');

            if ($file === false) {
                throw AbstractException::factory('OpenFile', 'Could not open cache file.');
            }

            if (fwrite($file, serialize($this->tldList)) === false) {
                throw AbstractException::factory('WriteFile', 'Could not open cache file for writing.');
            }

            fclose($file);
        }

        $this->loaded = true;
    }
276168
protected void readFromDB4Links()
        throws CacheReloadException
    {
        Connection con = null;
        try {
            con = Context.getConnection();
            final SQLSelect select = new SQLSelect()
                            .column(0, "TYPEID")
                            .column(0, "TOID")
                            .column(1, "TYPEID")
                            .column(1, "NAME")
                            .from("T_CMABSTRACT2ABSTRACT", 0)
                            .leftJoin("T_CMABSTRACT", 1, "ID", 0, "TOID")
                            .addPart(SQLPart.WHERE)
                            .addColumnPart(0, "FROMID")
                            .addPart(SQLPart.EQUAL)
                            .addValuePart(getId());

            final Statement stmt = con.createStatement();
            final ResultSet rs = stmt.executeQuery(select.getSQL());

            AbstractAdminObject.LOG.debug("Reading Links for '{}'", getName());

            final List<Object[]> values = new ArrayList<>();
            while (rs.next()) {
                final long conTypeId = rs.getLong(1);
                final long toId = rs.getLong(2);
                final long toTypeId = rs.getLong(3);
                final String toName = rs.getString(4);
                values.add(new Object[] { conTypeId, toId, toTypeId, toName.trim() });
            }
            rs.close();
            stmt.close();
            con.commit();
            con.close();
            for (final Object[] row : values) {
                final UUID conTypeUUID = Type.getUUID4Id((Long) row[0]);
                AbstractAdminObject.LOG.debug("     Connection Type UUID: {}", conTypeUUID);
                final UUID toTypeUUID = Type.getUUID4Id((Long) row[2]);
                AbstractAdminObject.LOG.debug("     To Type UUID: {}", toTypeUUID);
                if (conTypeUUID != null && toTypeUUID != null) {
                    setLinkProperty(conTypeUUID, (Long) row[1], toTypeUUID, String.valueOf(row[3]));
                    AbstractAdminObject.LOG.debug("     ID: {}, name: {}", row[1], row[3]);
                }
            }
        } catch (final SQLException e) {
            throw new CacheReloadException("could not read db links for " + "'" + getName() + "'", e);
            // CHECKSTYLE:OFF
        } catch (final RuntimeException e) {
            // CHECKSTYLE:ON
            throw new CacheReloadException("could not read db links for " + "'" + getName() + "'", e);
        } catch (final EFapsException e) {
            throw new CacheReloadException("could not read properties for " + "'" + getName() + "'", e);
        } finally {
            try {
                if (con != null && !con.isClosed()) {
                    con.close();
                }
            } catch (final SQLException e) {
                throw new CacheReloadException("Cannot read a type for an attribute.", e);
            }
        }
    }
1124000
@Override
    public String loadDataFromNetwork() throws Exception {
        try {
            Ln.d("Call web service " + url);
            return IOUtils.toString(new InputStreamReader(new URL(url).openStream(), CharEncoding.UTF_8));
        } catch (final MalformedURLException e) {
            Ln.e(e, "Unable to create URL");
            throw e;
        } catch (final IOException e) {
            Ln.e(e, "Unable to download content");
            throw e;
        }
    }
68625
public static void main(String[] args) throws Exception {

		ParameterTool params = ParameterTool.fromArgs(args);

		final int numPages = params.getInt("numPages", PageRankData.getNumberOfPages());
		final int maxIterations = params.getInt("iterations", 10);

		// set up execution environment
		final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

		// make the parameters available to the web ui
		env.getConfig().setGlobalJobParameters(params);

		// get input data
		DataSet<Long> pagesInput = getPagesDataSet(env, params);
		DataSet<Tuple2<Long, Long>> linksInput = getLinksDataSet(env, params);

		// assign initial rank to pages
		DataSet<Tuple2<Long, Double>> pagesWithRanks = pagesInput.
				map(new RankAssigner((1.0d / numPages)));

		// build adjacency list from link input
		DataSet<Tuple2<Long, Long[]>> adjacencyListInput =
				linksInput.groupBy(0).reduceGroup(new BuildOutgoingEdgeList());

		// set iterative data set
		IterativeDataSet<Tuple2<Long, Double>> iteration = pagesWithRanks.iterate(maxIterations);

		DataSet<Tuple2<Long, Double>> newRanks = iteration
				// join pages with outgoing edges and distribute rank
				.join(adjacencyListInput).where(0).equalTo(0).flatMap(new JoinVertexWithEdgesMatch())
				// collect and sum ranks
				.groupBy(0).aggregate(SUM, 1)
				// apply dampening factor
				.map(new Dampener(DAMPENING_FACTOR, numPages));

		DataSet<Tuple2<Long, Double>> finalPageRanks = iteration.closeWith(
				newRanks,
				newRanks.join(iteration).where(0).equalTo(0)
				// termination condition
				.filter(new EpsilonFilter()));

		// emit result
		if (params.has("output")) {
			finalPageRanks.writeAsCsv(params.get("output"), "\n", " ");
			// execute program
			env.execute("Basic Page Rank Example");
		} else {
			System.out.println("Printing result to stdout. Use --output to specify output path.");
			finalPageRanks.print();
		}
	}
166348
@Override
  protected void run() throws Exception {
    final ResourceLoader resourceLoader = new MojoResourceLoader(getRuntimeRealm(), getScriptpath());
    final Map<String, Object> context = createContext();
    final Map<String, Object> options = Maps.newHashMap();
    final ConsoleWindow console = getRuntime().createConsoleWindow();

    WindowHandle handle = console.open(getRuntimeRealm(), resourceLoader, context, options);
    handle.await();
  }
380755
public void init() throws UnavailableException
    {
        ServletContext config = getServletContext();
        _servletHandler = ((ServletHandler.Context) config).getServletHandler();
        _httpContext = _servletHandler.getHttpContext();

        _acceptRanges = getInitBoolean("acceptRanges");
        _dirAllowed = getInitBoolean("dirAllowed");
        _putAllowed = getInitBoolean("putAllowed");
        _delAllowed = getInitBoolean("delAllowed");
        _redirectWelcomeFiles = getInitBoolean("redirectWelcome");
        _minGzipLength = getInitInt("minGzipLength");

        String rrb = getInitParameter("relativeResourceBase");
        if (rrb != null)
        {
            try
            {
                _resourceBase = _httpContext.getBaseResource().addPath(rrb);
            }
            catch (Exception e)
            {
                log.warn(LogSupport.EXCEPTION, e);
                throw new UnavailableException(e.toString());
            }
        }

        String rb = getInitParameter("resourceBase");

        if (rrb != null && rb != null)
            throw new UnavailableException("resourceBase & relativeResourceBase");

        if (rb != null)
        {
            try
            {
                _resourceBase = Resource.newResource(rb);
            }
            catch (Exception e)
            {
                log.warn(LogSupport.EXCEPTION, e);
                throw new UnavailableException(e.toString());
            }
        }
        if (log.isDebugEnabled())
            log.debug("resource base = " + _resourceBase);

        if (_putAllowed)
            _AllowString += ", PUT";
        if (_delAllowed)
            _AllowString += ", DELETE";
        if (_putAllowed && _delAllowed)
            _AllowString += ", MOVE";
    }
456122
private function loadInstallationMap()
	{
		if (file_exists($this->mapFile)) {
			if (!is_readable($this->mapFile) || is_dir($this->mapFile)) {
				throw new \Exception(sprintf(
					'Cannot read map file at %s', $this->mapFile
				));
			}

			$this->installationMap = json_decode(file_get_contents($this->mapFile), TRUE);

			if ($this->installationMap === NULL) {
				throw new \Exception(sprintf(
					'Broken map file at %s', $this->mapFile
				));
			}
		}
	}
1103428
public void load() throws IOException {
        if (resource.toExternalForm().endsWith(".xml")) {
            // XML Format
            bundle = new XMLResourceBundle(resource.openStream());
        } else {
            // Properties file (loaded using UTF-8)
            bundle = new UTF8PropertiesResourceBundle(resource.openStream());
        }

        if (bundle.keySet().isEmpty()) {
            throw new IOException(resource.toExternalForm() + " is not a valid resource - no keys");
        }
    }
470615
private byte[] getLinkContent() throws IOException
   {
      ByteArrayOutputStream outStream = new ByteArrayOutputStream();

      byte[] firstItem = getFirstItem();
      writeInt(firstItem.length + 2, outStream);
      writeBytes(firstItem, outStream);

      byte[] lastItem = getLastItem();
      writeInt(lastItem.length + 2, outStream);
      writeBytes(lastItem, outStream);

      String[] pathes = servletPath.split("/");
      String root = pathes[pathes.length - 1];

      byte[] rootItem = getRootItem(root, servletPath);
      writeInt(rootItem.length + 2, outStream);
      writeBytes(rootItem, outStream);

      pathes = targetPath.split("/");
      StringBuilder curHref = new StringBuilder(servletPath);

      for (int i = 0; i < pathes.length; i++)
      {
         if ("".equals(pathes[i]))
         {
            continue;
         }
         String curName = pathes[i];
         curHref.append("/").append(curName);

         if (i < pathes.length - 1)
         {
            byte[] linkItem = getHreffedFolder(curName, curHref.toString());
            writeInt(linkItem.length + 2, outStream);
            writeBytes(linkItem, outStream);
         }
         else
         {
            byte[] linkFile = getHreffedFile(curName, curHref.toString());
            writeInt(linkFile.length + 2, outStream);
            writeBytes(linkFile, outStream);
         }

      }

      return outStream.toByteArray();
   }
1043719
public void process() {
		try {
			Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources("META-INF/persistence.xml");
			XMLInputFactory factory = XMLInputFactory.newInstance();
			List<String> persistenceUnits = new ArrayList<String>();
			
			while (urls.hasMoreElements()) {
				URL url = urls.nextElement();
				XMLStreamReader reader = factory.createXMLStreamReader(url.openStream());
				
				while (reader.hasNext()) {
					if (reader.next() == XMLStreamConstants.START_ELEMENT 
							&& reader.getName().getLocalPart().equals("persistence-unit")) {
						for (int i = 0; i < reader.getAttributeCount(); i++) {
							if (reader.getAttributeLocalName(i).equals("name")) {
								persistenceUnits.add(reader.getAttributeValue(i));
								break;
							}
						}
					}
				}
			}
			
			this.persistenceUnits = persistenceUnits;
		} catch (Exception e) {
			logger.error("Failed to parse persistence.xml", e);
		}
	}
695112
protected function _loadRawHeaders()
    {
        if($this->_rawHeaders !== NULL) return;

        $this->_rawHeaders = apache_request_headers();

        if($this->_rawHeaders === FALSE)
            throw new Exception("Could not get request headers");
    }
479440
public void load(String file) {
		Context context = factory.enterContext();
		
		try {
			URL url = Thread.currentThread().getContextClassLoader().getResource(file);
			
			if (url == null) {
				logger.debug("Configuration [" + file + "] does not exist");
				return;
			}
			
			File f = new File(url.getPath());
			
			if (f.exists()) {
				logger.info("Loading configuration [" + file + "]");
				context.evaluateReader(scope, new FileReader(f), file.substring(file.lastIndexOf("/") + 1), 1, null);
			}
			
		} catch (Exception e) {
			logger.error("Failed to load configuration [" + file + "]", e);
			throw new UncheckedException(e);
		} finally {
			Context.exit();
		}
	}
1217531
private void loadDataFromInternet() throws IOException {
		URL url = new URL(DATA_RETRIVE_URL);
		InputStream is = url.openStream();
		try {
			PHPFileParser fp = new PHPFileParser(is);
			createInternalDataStructre(fp.getSections());
		} finally {
			is.close();
		}
	}
1104894
public function load()
	{
		$filename = $this->getFile();
		if (!file_exists($filename))
			return;

		$json = file_get_contents($filename);
		if (strlen($json) == 0)
			return;

		$data = $this->decode($json);
		if ($data === null)
			throw new Exception('Error while trying to decode ' . $filename . '.');

		$this->data = $data;

		if (!$this->verify())
			throw new Exception($filename . ' failed checksum validation.');
	}