List of usage examples for java.io IOException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.searchcode.app.jobs.repository.IndexBaseRepoJob.java
/** * Indexes all the documents in the repository changed file effectively performing a delta update * Should only be called when there is a genuine update IE something was indexed previously and * has has a new commit.//from w ww. j a va 2s.c o m */ public void indexDocsByDelta(Path path, String repoName, String repoLocations, String repoRemoteLocation, RepositoryChanged repositoryChanged) { SearchcodeLib scl = Singleton.getSearchCodeLib(); // Should have data object by this point Queue<CodeIndexDocument> codeIndexDocumentQueue = Singleton.getCodeIndexQueue(); String fileRepoLocations = FilenameUtils.separatorsToUnix(repoLocations); // Used to hold the reports of what was indexed List<String[]> reportList = new ArrayList<>(); for (String changedFile : repositoryChanged.getChangedFiles()) { if (this.shouldJobPauseOrTerminate()) { return; } if (Singleton.getDataService().getPersistentDelete().contains(repoName)) { return; } String[] split = changedFile.split("/"); String fileName = split[split.length - 1]; changedFile = fileRepoLocations + "/" + repoName + "/" + changedFile; changedFile = changedFile.replace("//", "/"); CodeLinesReturn codeLinesReturn = this.getCodeLines(changedFile, reportList); if (codeLinesReturn.isError()) { break; } IsMinifiedReturn isMinified = this.getIsMinified(codeLinesReturn.getCodeLines(), fileName, reportList); if (isMinified.isMinified()) { break; } if (this.checkIfEmpty(codeLinesReturn.getCodeLines(), changedFile, reportList)) { break; } if (this.determineBinary(changedFile, fileName, codeLinesReturn.getCodeLines(), reportList)) { break; } String md5Hash = this.getFileMd5(changedFile); String languageName = Singleton.getFileClassifier().languageGuesser(changedFile, codeLinesReturn.getCodeLines()); String fileLocation = this.getRelativeToProjectPath(path.toString(), changedFile); String fileLocationFilename = changedFile.replace(fileRepoLocations, Values.EMPTYSTRING); String repoLocationRepoNameLocationFilename = changedFile; String newString = this.getBlameFilePath(fileLocationFilename); String codeOwner = this.getCodeOwner(codeLinesReturn.getCodeLines(), newString, repoName, fileRepoLocations, scl); if (this.LOWMEMORY) { try { Singleton.getCodeIndexer().indexDocument(new CodeIndexDocument( repoLocationRepoNameLocationFilename, repoName, fileName, fileLocation, fileLocationFilename, md5Hash, languageName, codeLinesReturn.getCodeLines().size(), StringUtils.join(codeLinesReturn.getCodeLines(), " "), repoRemoteLocation, codeOwner)); } catch (IOException ex) { Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + "\n with message: " + ex.getMessage()); } } else { this.sharedService.incrementCodeIndexLinesCount(codeLinesReturn.getCodeLines().size()); codeIndexDocumentQueue.add(new CodeIndexDocument(repoLocationRepoNameLocationFilename, repoName, fileName, fileLocation, fileLocationFilename, md5Hash, languageName, codeLinesReturn.getCodeLines().size(), StringUtils.join(codeLinesReturn.getCodeLines(), " "), repoRemoteLocation, codeOwner)); } if (this.LOGINDEXED) { reportList.add(new String[] { changedFile, "included", "" }); } } if (this.LOGINDEXED && reportList.isEmpty() == false) { this.logIndexed(repoName + "_delta", reportList); } for (String deletedFile : repositoryChanged.getDeletedFiles()) { deletedFile = fileRepoLocations + "/" + repoName + "/" + deletedFile; deletedFile = deletedFile.replace("//", "/"); Singleton.getLogger().info("Missing from disk, removing from index " + deletedFile); try { Singleton.getCodeIndexer().deleteByCodeId(DigestUtils.sha1Hex(deletedFile)); } catch (IOException ex) { Singleton.getLogger() .warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + " indexDocsByDelta deleteByFileLocationFilename for " + repoName + " " + deletedFile + "\n with message: " + ex.getMessage()); } } }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
public void setConfig(Map<String, Object> config) { try {/* w w w . j a v a 2 s . c o m*/ String rawJsonString = mObjectMapper.writeValueAsString(config); mSharedPreferences.edit().putString(buildPreferenceKey(), rawJsonString).commit(); resolverSaveUserConfig(); } catch (IOException e) { Log.e(TAG, "setConfig: " + e.getClass() + ": " + e.getLocalizedMessage()); } }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
/** * @return the Map<String, String> containing the Config information of this resolver *///from w w w .ja v a2s . c o m public Map<String, Object> getConfig() { String rawJsonString = mSharedPreferences.getString(buildPreferenceKey(), ""); try { return mObjectMapper.readValue(rawJsonString, Map.class); } catch (IOException e) { Log.e(TAG, "getConfig: " + e.getClass() + ": " + e.getLocalizedMessage()); } return new HashMap<String, Object>(); }
From source file:com.searchcode.app.jobs.IndexGitRepoJob.java
public void execute(JobExecutionContext context) throws JobExecutionException { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while (CodeIndexer.shouldPauseAdding()) { Singleton.getLogger().info("Pausing parser."); return;/* ww w .j ava2 s. c o m*/ } // Pull the next repo to index from the queue UniqueRepoQueue repoQueue = Singleton.getUniqueGitRepoQueue(); RepoResult repoResult = repoQueue.poll(); AbstractMap<String, Integer> runningIndexGitRepoJobs = Singleton.getRunningIndexRepoJobs(); if (repoResult != null && !runningIndexGitRepoJobs.containsKey(repoResult.getName())) { Singleton.getLogger().info("Indexing " + repoResult.getName()); try { runningIndexGitRepoJobs.put(repoResult.getName(), (int) (System.currentTimeMillis() / 1000)); JobDataMap data = context.getJobDetail().getJobDataMap(); String repoName = repoResult.getName(); String repoRemoteLocation = repoResult.getUrl(); String repoUserName = repoResult.getUsername(); String repoPassword = repoResult.getPassword(); String repoBranch = repoResult.getBranch(); String repoLocations = data.get("REPOLOCATIONS").toString(); this.LOWMEMORY = Boolean.parseBoolean(data.get("LOWMEMORY").toString()); // Check if sucessfully cloned, and if not delete and restart boolean cloneSucess = checkCloneUpdateSucess(repoLocations + repoName); if (cloneSucess == false) { // Delete the folder and delete from the index try { FileUtils.deleteDirectory(new File(repoLocations + "/" + repoName + "/")); CodeIndexer.deleteByReponame(repoName); } catch (IOException ex) { Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + "\n with message: " + ex.getMessage()); } } deleteCloneUpdateSuccess(repoLocations + "/" + repoName); String repoGitLocation = repoLocations + "/" + repoName + "/.git/"; File f = new File(repoGitLocation); boolean existingRepo = f.exists(); boolean useCredentials = repoUserName != null && !repoUserName.isEmpty(); RepositoryChanged repositoryChanged = null; if (existingRepo) { repositoryChanged = this.updateGitRepository(repoName, repoRemoteLocation, repoUserName, repoPassword, repoLocations, repoBranch, useCredentials); } else { repositoryChanged = this.cloneGitRepository(repoName, repoRemoteLocation, repoUserName, repoPassword, repoLocations, repoBranch, useCredentials); } // Write file indicating we have sucessfully cloned createCloneUpdateSuccess(repoLocations + "/" + repoName); // If the last index was not sucessful, then trigger full index boolean indexsuccess = checkIndexSucess(repoGitLocation); if (repositoryChanged.isChanged() || indexsuccess == false) { Singleton.getLogger().info("Update found indexing " + repoRemoteLocation); this.updateIndex(repoName, repoLocations, repoRemoteLocation, existingRepo, repositoryChanged); } } finally { // Clean up the job runningIndexGitRepoJobs.remove(repoResult.getName()); } } }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
public void reportStreamUrl(String qid, String url, String stringifiedHeaders) { try {/* w w w .java 2 s.c om*/ Map<String, String> headers = null; if (stringifiedHeaders != null) { headers = mObjectMapper.readValue(stringifiedHeaders, Map.class); } String resultKey = mQueryKeys.get(qid); PipeLine.getInstance().sendStreamUrlReportBroadcast(resultKey, url, headers); } catch (IOException e) { Log.e(TAG, "reportStreamUrl: " + e.getClass() + ": " + e.getLocalizedMessage()); } }
From source file:com.maverick.ssl.SSLHandshakeProtocol.java
private void calculateMasterSecret() throws SSLException { // #ifdef DEBUG log.debug(Messages.getString("SSLHandshakeProtocol.calculatingMasterSecret")); //$NON-NLS-1$ // #endif//from w w w .java 2 s.c o m try { MD5Digest md5 = new MD5Digest(); SHA1Digest sha1 = new SHA1Digest(); ByteArrayOutputStream out = new ByteArrayOutputStream(); String[] mixers = new String[] { "A", "BB", "CCC" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ for (int i = 0; i < mixers.length; i++) { md5.reset(); sha1.reset(); sha1.update(mixers[i].getBytes(), 0, mixers[i].getBytes().length); sha1.update(premasterSecret, 0, premasterSecret.length); sha1.update(clientRandom, 0, clientRandom.length); sha1.update(serverRandom, 0, serverRandom.length); md5.update(premasterSecret, 0, premasterSecret.length); byte[] tmp = new byte[sha1.getDigestSize()]; sha1.doFinal(tmp, 0); md5.update(tmp, 0, tmp.length); tmp = new byte[md5.getDigestSize()]; md5.doFinal(tmp, 0); out.write(tmp); } masterSecret = out.toByteArray(); } catch (IOException ex) { throw new SSLException(SSLException.INTERNAL_ERROR, ex.getMessage() == null ? ex.getClass().getName() : ex.getMessage()); } }
From source file:org.xmlblackbox.test.infrastructure.FlowControl.java
private void executeNode(XmlElement obj, int step) throws Exception { try {/*from w ww. j a va 2s.c o m*/ if (obj instanceof CheckDatabase) { CheckDatabase dbCheck = (CheckDatabase) obj; log.info("checkDB connection " + dbCheck.getConnection()); Connection connDbCheck = memory.getConnectionByName(dbCheck.getConnection()); dbCheck.checkDB(memory, new DatabaseConnection(connDbCheck), step); } else if (obj instanceof ClientWeb) { httpClient = (ClientWeb) obj; Properties webNavigationProp = memory.getOrCreateRepository(Repository.WEB_NAVIGATION); webNavigationProp.putAll(httpClient.getParameters()); Properties parametersProperties = new Properties(); log.info("httpClient.getParameters() " + httpClient.getParameters()); parametersProperties.putAll(httpClient.getParameters()); log.info("parametersProperties " + parametersProperties); memory.overrideRepository(Repository.PARAMETERS, parametersProperties); if (httpClient.getType().equals(ClientWeb.HTTPTESTER)) { httpTestCase = httpClient.executeHttpClient(httpClient, httpTestCase, memory); webNavigationProp.putAll(httpTestCase.getResultVariables()); } else if (httpClient.getType().equals(ClientWeb.SELENIUM)) { selenium = httpClient.executeSelenium(memory, selenium); } else { throw new TestException("HTTP-CLIENT type " + httpClient.getType() + " not exist!!!"); } } else if (obj instanceof HTTPUploader) { httpUploader = (HTTPUploader) obj; Properties webNavigationProp = memory.getOrCreateRepository(Repository.WEB_NAVIGATION); webNavigationProp.putAll(httpClient.getParameters()); memory.getOrCreateRepository(Repository.WEB_NAVIGATION) .putAll(memory.getRepository(Repository.FILE_PROPERTIES)); memory.getOrCreateRepository(Repository.WEB_NAVIGATION).putAll(httpUploader.getParameters()); httpUploader.uploadFile(memory, httpUploader); } else if (obj instanceof WebServiceClient) { WebServiceClient webServiceClient = (WebServiceClient) obj; //log.info("Eseguito il wsc "+webServiceClient.getNome()); webServiceClient.executeWebServiceClient(); } else if (obj instanceof WaitTask) { WaitTask waitTask = (WaitTask) obj; log.info("Eseguito il waitTask " + waitTask.getNome()); waitTask.waitTask(memory); } else if (obj instanceof RunPlugin) { RunPlugin runPlugin = (RunPlugin) obj; log.info("Executed plugin: " + runPlugin.getTemplateClass()); runPlugin.executePlugin(memory); log.info("memory: " + memory.getRepository(Repository.RUN_PLUGIN)); } else if (obj instanceof XmlValidate) { XmlValidate xmlValidate = (XmlValidate) obj; xmlValidate.executeValidazioneXml(); } else if (obj instanceof XmlDbConnections) { XmlDbConnections xmlDbConnections = (XmlDbConnections) obj; Iterator connectionList = xmlDbConnections.getDbConnectionList().iterator(); while (connectionList.hasNext()) { DbConnection connection = (DbConnection) connectionList.next(); Connection conn = DBConnection.getConnection(connection.getDriver(), connection.getDbUrl(), connection.getUsername(), connection.getPassword()); log.info("connection.getName() " + connection.getName()); log.info("conn " + conn); memory.setConnection(connection.getName(), conn); } } else if (obj instanceof SetVariable) { log.debug("setVariable "); SetVariable setVariable = (SetVariable) obj; Iterator<Set> iter = setVariable.getSetList().iterator(); log.debug("setVariable.getSetList().size() " + setVariable.getSetList().size()); while (iter.hasNext()) { Set currentSet = iter.next(); log.debug("setVariable.getRepositoryName() " + setVariable.getRepositoryName()); log.debug("currentSet.getNome() " + currentSet.getNome()); log.debug("currentSet.getValue() " + currentSet.getValue()); log.debug("currentSet.getType() " + currentSet.getType()); if (currentSet.getType() != null) { if (currentSet.getType().equals(Set.VALUE_TYPE)) { memory.set(setVariable.getRepositoryName(), currentSet.getNome(), currentSet.getValue()); } else if (currentSet.getType().equals(Set.XML_TYPE)) { SetVariable.setVariableFromXml(currentSet, memory.getOrCreateRepository(setVariable.getRepositoryName())); } else if (currentSet.getType().equals(Set.DB_TYPE)) { SetVariable.setVariableFromDb(currentSet, memory); } } else { throw new TestException( "The type in SET tag (" + currentSet.getNome() + ") is not correctly set"); } } } else if (obj instanceof RunQuery) { RunQuery executeQuery = (RunQuery) obj; Iterator<Query> iter = executeQuery.getQueryList().iterator(); log.info("ExecuteQuery"); log.info("executeQuery.getConnection() " + executeQuery.getConnection()); while (iter.hasNext()) { Query query = iter.next(); IDatabaseConnection conn = new DatabaseConnection( (Connection) memory.getConnectionByName(query.getConnection())); if (conn == null || conn.getConnection() == null) { throw new DbCheckException("Connection \"" + query.getConnection() + "\" not found"); } log.info("Run query " + query.getQuery() + " about xml object " + query.getNome()); if (query.getType().equals(Query.UPDATE) || query.getType().equals(Query.INSERT)) { int result = conn.getConnection().createStatement().executeUpdate(query.getQuery()); log.info(query.getType() + "result " + result); } else { boolean result = conn.getConnection().createStatement().execute(query.getQuery()); log.info(query.getType() + "result " + result); } } } else if (obj instanceof CheckInsertXmlContent) { CheckInsertXmlContent checkXmlContent = (CheckInsertXmlContent) obj; Iterator<XmlCheckRow> iter = checkXmlContent.getCheckXmlList().iterator(); XmlObject xobj = checkXmlContent.getXmlObject(); while (iter.hasNext()) { XmlRowInterface xmlRow = iter.next(); if (xmlRow.getType().equals(XmlCheckRow.TYPE)) { xobj = checkXmlContent.checkValueInXml(xobj, (XmlCheckRow) xmlRow, memory); } else if (xmlRow.getType().equals(XmlInsertRow.TYPE)) { xobj = checkXmlContent.insertValueInXml(xobj, (XmlInsertRow) xmlRow, memory); } else if (xmlRow.getType().equals(XmlInsertRemoveNodeRow.TYPE_INSERT)) { log.info("((XmlInsertRemoveNodeRow)xmlRow).getXPath() " + ((XmlInsertRemoveNodeRow) xmlRow).getXPath()); xobj = checkXmlContent.insertNodeInXml(xobj, (XmlInsertRemoveNodeRow) xmlRow, memory); log.info("xobj.xmlText() " + xobj.xmlText()); } } try { if (checkXmlContent.getFileOutput() != null) { log.info("File output salvato " + checkXmlContent.getFileOutput()); XmlOptions xmlOptions = new XmlOptions(); xmlOptions.setSavePrettyPrint(); xobj.save(new File(checkXmlContent.getFileOutput()), xmlOptions); } } catch (IOException e) { throw new TestException(e, "IOException"); } } } catch (TestException e) { e.setErrorMessage("Node Failed " + obj.getName() + ". " + e.toString()); log.error(e.getClass().getSimpleName() + " [!] Execution Node Failed : ", e); throw e; } catch (Exception e) { log.error(e.getClass().getSimpleName() + " [!] Execution Node Failed : ", e); throw e; } }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
public void callback(final int callbackId, final String responseText, final Map<String, List<String>> responseHeaders, final int status, final String statusText) { final Map<String, String> headers = new HashMap<String, String>(); for (String key : responseHeaders.keySet()) { if (key != null) { String concatenatedValues = ""; for (int i = 0; i < responseHeaders.get(key).size(); i++) { if (i > 0) { concatenatedValues += "\n"; }//from www . j ava2 s.c om concatenatedValues += responseHeaders.get(key).get(i); } headers.put(key, concatenatedValues); } } try { String headersString = mObjectMapper.writeValueAsString(headers); loadUrl("javascript: Tomahawk.callback(" + callbackId + "," + "'" + StringEscapeUtils.escapeJavaScript(responseText) + "'," + "'" + StringEscapeUtils.escapeJavaScript(headersString) + "'," + status + "," + "'" + StringEscapeUtils.escapeJavaScript(statusText) + "');"); } catch (IOException e) { Log.e(TAG, "callback: " + e.getClass() + ": " + e.getLocalizedMessage()); } }
From source file:com.maverick.ssl.SSLHandshakeProtocol.java
private void sendClientHello() throws SSLException { // #ifdef DEBUG log.debug(Messages.getString("SSLHandshakeProtocol.sendingClientHello")); //$NON-NLS-1$ // #endif/*from w w w .j a v a2 s . c o m*/ ByteArrayOutputStream msg = new ByteArrayOutputStream(); try { clientRandom = new byte[32]; context.getRND().nextBytes(clientRandom); long time = System.currentTimeMillis(); clientRandom[0] = (byte) ((time >> 24) & 0xFF); clientRandom[1] = (byte) ((time >> 16) & 0xFF); clientRandom[2] = (byte) ((time >> 8) & 0xFF); clientRandom[3] = (byte) (time & 0xFF); // Write the version msg.write(SSLTransportImpl.VERSION_MAJOR); msg.write(SSLTransportImpl.VERSION_MINOR); // Write the random bytes msg.write(clientRandom); // Write the session identifier - currently were not caching so zero // length msg.write(0); // Write the cipher ids - TODO: we need to set the preferred as // first SSLCipherSuiteID[] ids = context.getCipherSuiteIDs(); msg.write(0); msg.write(ids.length * 2); for (int i = 0; i < ids.length; i++) { msg.write(ids[i].id1); msg.write(ids[i].id2); } // Compression - no compression is currently supported msg.write(1); msg.write(0); } catch (IOException ex) { throw new SSLException(SSLException.INTERNAL_ERROR, ex.getMessage() == null ? ex.getClass().getName() : ex.getMessage()); } sendMessage(CLIENT_HELLO_MSG, msg.toByteArray()); currentHandshakeStep = CLIENT_HELLO_MSG; }
From source file:net.oneandone.jasmin.main.Servlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {/*from w w w . j a v a2 s.c o m*/ doGetUnchecked(request, response); } catch (IOException e) { // I can't compile against this class because the servlet api does not officially // report this situation ... // See http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/connector/ClientAbortException.html if (e.getClass().getName().equals("org.apache.catalina.connector.ClientAbortException")) { // this is not an error: the client browser closed the response stream, e.g. because // the user already left the page LOG.info("aborted by client", e); } else { error(request, "get", e); } throw e; } catch (RuntimeException | Error e) { error(request, "get", e); throw e; } }