List of usage examples for java.lang Exception Exception
public Exception(Throwable cause)
From source file:at.illecker.hama.rootbeer.examples.matrixmultiplication.cpu.MatrixMultiplicationBSPCpu.java
public static void main(String[] args) throws Exception { // Defaults/*from w w w . ja v a 2s . c om*/ int numRowsA = 1024; int numColsA = 1024; int numRowsB = 1024; int numColsB = 1024; boolean isDebugging = false; Configuration conf = new HamaConfiguration(); BSPJobClient jobClient = new BSPJobClient(conf); ClusterStatus cluster = jobClient.getClusterStatus(true); if (args.length > 0) { if (args.length == 6) { conf.setInt("bsp.peers.num", Integer.parseInt(args[0])); numRowsA = Integer.parseInt(args[1]); numColsA = Integer.parseInt(args[2]); numRowsB = Integer.parseInt(args[3]); numColsB = Integer.parseInt(args[4]); isDebugging = Boolean.parseBoolean(args[5]); } else { System.out.println("Wrong argument size!"); System.out.println(" Argument1=numBspTask"); System.out.println(" Argument2=numRowsA | Number of rows of the first input matrix"); System.out.println(" Argument3=numColsA | Number of columns of the first input matrix"); System.out.println(" Argument4=numRowsB | Number of rows of the second input matrix"); System.out.println(" Argument5=numColsB | Number of columns of the second input matrix"); System.out.println(" Argument6=debug | Enable debugging (true|false)"); return; } } else { conf.setInt("bsp.peers.num", cluster.getMaxTasks()); } conf.setBoolean(CONF_DEBUG, isDebugging); LOG.info("NumBspTask: " + conf.getInt("bsp.peers.num", 0)); LOG.info("numRowsA: " + numRowsA); LOG.info("numColsA: " + numColsA); LOG.info("numRowsB: " + numRowsB); LOG.info("numColsB: " + numColsB); LOG.info("isDebugging: " + isDebugging); LOG.info("outputPath: " + OUTPUT_DIR); if (numColsA != numRowsB) { throw new Exception("Cols of MatrixA != rows of MatrixB! (" + numColsA + "!=" + numRowsB + ")"); } // Create random DistributedRowMatrix // use constant seeds to get reproducible results // Matrix A DistributedRowMatrix.createRandomDistributedRowMatrix(conf, numRowsA, numColsA, new Random(42L), MATRIX_A_PATH, false); // Matrix B is stored transposed DistributedRowMatrix.createRandomDistributedRowMatrix(conf, numRowsB, numColsB, new Random(1337L), MATRIX_B_PATH, true); // Load DistributedRowMatrix a and b DistributedRowMatrix a = new DistributedRowMatrix(MATRIX_A_PATH, OUTPUT_DIR, numRowsA, numColsA); a.setConf(conf); DistributedRowMatrix b = new DistributedRowMatrix(MATRIX_B_PATH, OUTPUT_DIR, numRowsB, numColsB); b.setConf(conf); // MatrixMultiply all within a new BSP job long startTime = System.currentTimeMillis(); DistributedRowMatrix c = a.multiplyBSP(b, MATRIX_C_PATH, false); System.out.println("MatrixMultiplicationCpu using Hama finished in " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds"); // Verification // Overwrite matrix B, NOT transposed for verification check DistributedRowMatrix.createRandomDistributedRowMatrix(conf, numRowsB, numColsB, new Random(1337L), MATRIX_B_PATH, false); b = new DistributedRowMatrix(MATRIX_B_PATH, OUTPUT_DIR, numRowsB, numColsB); b.setConf(conf); DistributedRowMatrix d = a.multiplyJava(b, MATRIX_D_PATH); if (c.verify(d)) { System.out.println("Verify PASSED!"); } else { System.out.println("Verify FAILED!"); } if (isDebugging) { System.out.println("Matrix A:"); a.printDistributedRowMatrix(); System.out.println("Matrix B:"); b.printDistributedRowMatrix(); System.out.println("Matrix C:"); c.printDistributedRowMatrix(); System.out.println("Matrix D:"); d.printDistributedRowMatrix(); printOutput(conf); } }
From source file:com.edge.media.service.util.HttpUtil.java
public void verifyUrl(String url, String path, String suffix) throws Exception { HttpClient client = new HttpClient(); HttpMethod method = new HeadMethod(url + path + suffix); int statusCode = 0; try {// ww w.j av a2 s . co m statusCode = client.executeMethod(method); } catch (IOException e) { // do nothing } method.releaseConnection(); if (statusCode != HttpStatus.SC_OK) { StringBuilder err = new StringBuilder("Stream does not exist: "); err.append(path); err.append(", "); err.append(statusCode); throw new Exception(err.toString()); } }
From source file:account.dao.ContactDao.java
public void addContact(ContactDTO contactDTO) throws Exception { String email = contactDTO.getEmail(); boolean isContactPresent = checkThatContactCreated(contactDTO); if (isContactPresent) { throw new Exception("Contact with email " + email + " has allready created"); }//from w w w .j a v a 2s .c om Contact contact = new Contact(); contact.setFirstName(contactDTO.getFirstName()); contact.setLastName(contactDTO.getLastName()); contact.setBirthDate(contactDTO.getBirthDate()); contact.setHobbies(createHobbies(contactDTO.getHobbies())); contact.setPlaces(createPlaces(contactDTO.getPlaces())); contact.setEmail(email); contactList.add(contact); System.out.println("Added contact : " + contact); }
From source file:com.grepsound.requests.FollowRequest.java
@Override public Users loadDataFromNetwork() throws Exception { String url;//w ww . j av a 2s . c om switch (state) { case FOLLOWER: url = "/me/followers"; break; case FOLLOWING: url = "/me/followings"; break; default: throw new Exception("state must be FOLLOWERS or FOLLOWING"); } HttpResponse resp = Api.wrapper.get(Request.to(url)); JSONArray result = new JSONArray(Http.getString(resp)); return new Users(result); }
From source file:cat.ogasoft.protocolizer.processor.CompilerPhase.java
public static void processCompiler(RoundEnvironment roundEnv) throws CompilerException { try {//from w w w .jav a 2 s . co m String protocPath = "src" + File.separatorChar + "cat" + File.separatorChar + "ogasoft" + File.separatorChar + "protocolizer" + File.separatorChar + "protoc"; DefaultExecutor de = new DefaultExecutor(); for (Element element : roundEnv.getElementsAnnotatedWith(ProtoFileV2.Compiler.class)) { ProtoFileV2.Compiler compiler = element.getAnnotation(ProtoFileV2.Compiler.class); if (compiler.compile()) { String base = protocPath.replace('.', File.separatorChar); File dst = new File(base); if (!dst.exists() && !dst.mkdirs()) { throw new Exception("Cann not be created directory " + dst.getAbsolutePath()); } File rootDirectori = new File(base); //Compile all the files in compiler.protoFilePaths() FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().toLowerCase().endsWith(".proto"); } }; for (File protoc : rootDirectori.listFiles(filter)) { String target = base + File.separatorChar + protoc.getName(); LOG.info("\tCompiling " + target + "..."); CommandLine cmd = CommandLine.parse(compiler.command() + " --proto_path=" + protocPath + " " + compiler.language().option + "=src " + target); int result = de.execute(cmd); if (result != 0) { throw new CompilerException("HO ho... somthing went wrong, code: " + result); } LOG.info("\t" + target + " compiled"); } } } } catch (Exception e) { //Any exception is a CompilerException. throw new CompilerException(e.getMessage()); } }
From source file:com.codebutler.farebot.card.desfire.DesfireFileSettings.java
public static DesfireFileSettings Create(byte[] data) throws Exception { byte fileType = (byte) data[0]; ByteArrayInputStream stream = new ByteArrayInputStream(data); if (fileType == STANDARD_DATA_FILE || fileType == BACKUP_DATA_FILE) return new StandardDesfireFileSettings(stream); else if (fileType == LINEAR_RECORD_FILE || fileType == CYCLIC_RECORD_FILE) return new RecordDesfireFileSettings(stream); else if (fileType == VALUE_FILE) throw new UnsupportedOperationException("Value files not yet supported"); else/*from w ww . j a va 2 s . com*/ throw new Exception("Unknown file type: " + Integer.toHexString(fileType)); }
From source file:com.healthcit.analytics.businessdelegates.ModuleMetadataManager.java
/** * Loads module metadata// w w w . jav a 2 s .com */ public String loadModuleMetaData() throws Exception { String moduleMetadata = couchDb.getAttachment(PropertyUtils.getProperty("couchDBModuleMetadataDoc")); if (StringUtils.isEmpty(moduleMetadata)) throw new Exception("ERROR: Could not load the module metadata"); else return moduleMetadata; }
From source file:com.netsteadfast.greenstep.util.JFreeChartDataMapperUtils.java
public static Map<String, Object> fillBarDataMap(String categoryLabel, String valueLabel, String title, List<String> names, List<Float> values, List<String> colors, int width, int height, boolean horizontal) throws Exception { if (names == null || values == null || colors == null || names.size() != values.size() || names.size() != colors.size() || names.size() < 1) { throw new Exception(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_INCORRECT)); }//w ww . java 2 s .com Map<String, Object> dataMap = new HashMap<String, Object>(); dataMap.put("categoryLabel", categoryLabel); dataMap.put("valueLabel", valueLabel); dataMap.put("title", title); dataMap.put("names", names); dataMap.put("values", values); dataMap.put("colors", colors); dataMap.put("width", width); dataMap.put("height", height); dataMap.put("horizontal", (horizontal ? YesNo.YES : YesNo.NO)); return dataMap; }
From source file:nl.coralic.beta.sms.utils.http.HttpHandler.java
private static List<NameValuePair> createPostData(HashMap<String, String> arguments) throws Exception { List<NameValuePair> postdata = new ArrayList<NameValuePair>(); if (arguments != null) { for (String key : arguments.keySet()) { postdata.add(new BasicNameValuePair(key, arguments.get(key))); }/*from w w w. j a v a2s.c o m*/ return postdata; } throw new Exception("No arguments"); }
From source file:Main.java
/** * Gets the child of the specified element having the * specified name. If the child with this name doesn't exist * then the supplied default element is returned instead. * * @param element the parent element * @param tagName the name of the desired child * @param defaultElement the element to return if the child * doesn't exist/* w w w .j a v a2 s. com*/ * @return either the named child or the supplied default */ public static Element getOptionalChild(Element element, String tagName, Element defaultElement) throws Exception { final Iterator goodChildren = getChildrenByTagName(element, tagName); if (goodChildren != null && goodChildren.hasNext()) { final Element child = (Element) goodChildren.next(); if (goodChildren.hasNext()) { throw new Exception("expected only one " + tagName + " tag"); } return child; } else { return defaultElement; } }