List of usage examples for java.util Arrays copyOfRange
public static boolean[] copyOfRange(boolean[] original, int from, int to)
From source file:annis.gui.servlets.ResourceServlet.java
@Override @SuppressWarnings("unchecked") public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream outStream = response.getOutputStream(); String completePath = request.getPathInfo(); if (completePath == null) { response.sendError(404, "must provide a valid and existing path with a vistype"); return;// w ww.j av a 2 s . com } // remove trailing / completePath = completePath.substring(1); String[] pathComponents = completePath.split("/"); String vistype = pathComponents[0]; if (pathComponents.length < 2) { response.sendError(404, "must provide a valid and existing path"); return; } String path = StringUtils.join(Arrays.copyOfRange(pathComponents, 1, pathComponents.length), "/"); // get the visualizer for this vistype ResourcePlugin vis = resourceRegistry.get(vistype); if (vis == null) { response.sendError(500, "There is no resource with the short name " + vistype); } else if (path.endsWith(".class")) { response.sendError(403, "illegal class path access"); } else { URL resource = vis.getClass().getResource(path); if (resource == null) { response.sendError(404, path + " not found"); } else { // check if it is new URLConnection resourceConnection = resource.openConnection(); long resourceLastModified = resourceConnection.getLastModified(); long requestLastModified = request.getDateHeader("If-Modified-Since"); if (requestLastModified != -1 && resourceLastModified <= requestLastModified) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); } else { response.addDateHeader("Last-Modified", resourceLastModified); if ("localhost".equals(request.getServerName())) { // does always expire right now response.addDateHeader("Expires", new Date().getTime()); } else { // expires in one minute per default response.addDateHeader("Expires", new Date().getTime() + 60000); } // not in cache, stream out String mimeType = getServletContext().getMimeType(path); response.setContentType(mimeType); if (mimeType.startsWith("text/")) { response.setCharacterEncoding("UTF-8"); } OutputStream bufferedOut = new BufferedOutputStream(outStream); InputStream resourceInStream = new BufferedInputStream(resource.openStream()); try { int v = -1; while ((v = resourceInStream.read()) != -1) { bufferedOut.write(v); } } finally { resourceInStream.close(); bufferedOut.flush(); outStream.flush(); } } } } }
From source file:com.itemanalysis.psychometrics.analysis.AbstractDiffFunction.java
/** * Numerically compute gradientAt by the central difference method. Override this method * when the analytic gradientAt is available. * * * @param x// w w w. ja va 2s.com * @return */ public double[] gradient(double[] x) { int n = x.length; double[] grd = new double[n]; double[] u1 = new double[n]; double[] u2 = new double[n]; double f1 = 0.0; double f2 = 0.0; double stepSize = 0.0001; for (int i = 0; i < n; i++) { u1 = Arrays.copyOfRange(x, 0, x.length); u2 = Arrays.copyOfRange(x, 0, x.length); // stepSize = Math.sqrt(EPSILON)*(Math.abs(x[i])+1.0);//from SAS manual on nlp procedure u1[i] = (x[i] + stepSize); u2[i] = (x[i] - stepSize); f1 = value(u1); f2 = value(u2); grd[i] = (f1 - f2) / (2.0 * stepSize); } return grd; }
From source file:com.redsqirl.workflow.utils.FileStream.java
public static byte[] decryptFile(File in) throws Exception { //Decrypt the file data: byte[] encData; //Read in the file: FileInputStream inStream = new FileInputStream(in); encData = new byte[(int) in.length()]; inStream.read(encData);/* ww w. j a v a2 s . c o m*/ inStream.close(); byte[] decData = decrypt(encData); //Figure out how much padding to remove int padCount = (int) decData[decData.length - 1]; //Naive check, will fail if plaintext file actually contained //this at the end //For robust check, check that padCount bytes at the end have same value if (padCount >= 1 && padCount <= 8) { decData = Arrays.copyOfRange(decData, 0, decData.length - padCount); } //Write the decrypted data to a new file: return decData; }
From source file:in.dream_lab.bm.stream_iot.storm.bolts.IoTPredictionBolts.FIT.ParseProjectTAXIPredictBolt.java
@Override public void execute(Tuple input) { String rowString = input.getStringByField("RowString"); String msgId = input.getStringByField("MSGID"); {/*www. ja va2 s.c o m*/ String[] rowStringArray = rowString.split(","); sensorDetails = StringUtils.join(Arrays.copyOfRange(rowStringArray, 0, 3), ","); //TODO: ts to lat sensorID = rowStringArray[0]; observedValArr = StringUtils.join(Arrays.copyOfRange(rowStringArray, 4, 17), ","); // temp to aq if (l.isInfoEnabled()) l.info("sensorDetails : " + sensorDetails + "observedValArr" + observedValArr); collector.emit(new Values(sensorDetails, sensorID, observedValArr, msgId, "parse")); } }
From source file:net.sourceforge.fenixedu.domain.phd.serviceRequests.PhdDocumentRequestCreateBean.java
private void setGivenAndFamilyNames() { final Person person = getPhdIndividualProgramProcess().getPerson(); if (StringUtils.isEmpty(person.getGivenNames())) { String[] parts = person.getName().split("\\s+"); int split = parts.length > 3 ? 2 : 1; setGivenNames(StringUtils.join(Arrays.copyOfRange(parts, 0, split), " ")); setFamilyNames(StringUtils.join(Arrays.copyOfRange(parts, split, parts.length), " ")); } else {//from ww w.java2 s . c om setGivenNames(person.getGivenNames()); setFamilyNames(person.getFamilyNames()); } }
From source file:com.haulmont.cuba.gui.app.core.appproperties.AppPropertiesDatasource.java
List<AppPropertyEntity> createEntitiesTree(List<AppPropertyEntity> entities) { List<AppPropertyEntity> resultList = new ArrayList<>(); for (AppPropertyEntity entity : entities) { String[] parts = entity.getName().split("\\."); AppPropertyEntity parent = null; for (int i = 0; i < parts.length; i++) { String[] currParts = Arrays.copyOfRange(parts, 0, i + 1); String part = parts[i]; if (i < parts.length - 1) { Optional<AppPropertyEntity> parentOpt = resultList.stream().filter(e -> { return e.getCategory() && nameEquals(currParts, e); }).findFirst();//from w ww . j a v a 2 s . c om if (parentOpt.isPresent()) { parent = parentOpt.get(); } else { AppPropertyEntity categoryEntity = new AppPropertyEntity(); categoryEntity.setParent(parent); categoryEntity.setName(part); resultList.add(categoryEntity); parent = categoryEntity; } } else { entity.setParent(parent); entity.setCategory(false); resultList.add(entity); } } } // remove duplicates from global configs for (Iterator<AppPropertyEntity> iter = resultList.iterator(); iter.hasNext();) { AppPropertyEntity entity = iter.next(); resultList.stream().filter(e -> e != entity && nameParts(e).equals(nameParts(entity))).findFirst() .ifPresent(e -> iter.remove()); } return resultList; }
From source file:com.bunjlabs.fuga.templates.TemplateApi.java
/** * * @param args Input arguments//from w w w .j a v a 2 s .c o m * @return Produced string */ public String msg(Object... args) { if (args.length == 0) { return ""; } if (args.length == 1) { return args[0] != null ? ctx.msg().get(args[0].toString()) : ""; } return ctx.msg().get(args[0].toString(), Arrays.copyOfRange(args, 1, args.length)); }
From source file:com.ibm.crail.storage.rdma.RdmaStorageTier.java
public void init(CrailConfiguration conf, String[] args) throws Exception { if (args != null) { Option interfaceOption = Option.builder("i").desc("interface to start server on").hasArg().build(); Option portOption = Option.builder("p").desc("port to start server on").hasArg().build(); Options options = new Options(); options.addOption(interfaceOption); options.addOption(portOption);/*ww w . jav a 2 s. c o m*/ CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length)); if (line.hasOption(interfaceOption.getOpt())) { String ifname = line.getOptionValue(interfaceOption.getOpt()); LOG.info("using custom interface " + ifname); conf.set(RdmaConstants.STORAGE_RDMA_INTERFACE_KEY, ifname); } if (line.hasOption(portOption.getOpt())) { String port = line.getOptionValue(portOption.getOpt()); LOG.info("using custom port " + port); conf.set(RdmaConstants.STORAGE_RDMA_PORT_KEY, port); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("RDMA storage tier", options); System.exit(-1); } } RdmaConstants.updateConstants(conf); RdmaConstants.verify(); }
From source file:energy.usef.core.data.participant.Participant.java
public void setPublicKeysFromString(String concatenatedKeys) { if (concatenatedKeys == null) { return;//w w w . j av a2s.co m } if (!concatenatedKeys.startsWith(CS1_PREFIX)) { throw new IllegalArgumentException("Keys does not have an recognized prefix."); } String actualConcatenatedKey = concatenatedKeys.substring(CS1_PREFIX.length()); byte[] decodedKey = Base64.decodeBase64(actualConcatenatedKey); byte[] firstKey = Arrays.copyOfRange(decodedKey, FIRST_KEY_INDEX, SECOND_KEY_INDEX); setPublicKeys(Arrays.asList(Base64.encodeBase64String(firstKey), Base64.encodeBase64String(new byte[SECOND_KEY_SIZE]))); }
From source file:org.mitre.secretsharing.server.JoinServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); resp.setContentType("application/json"); try {/* ww w. j av a 2 s . c o m*/ Request jreq = mapper.readValue(req.getParameter("q"), Request.class); if (jreq.parts == null) throw new IllegalArgumentException(); Part[] parts = new Part[jreq.parts.size()]; for (int i = 0; i < parts.length; i++) parts[i] = PartFormats.parse(jreq.parts.get(i)); byte[] secret = parts[0].join(Arrays.copyOfRange(parts, 1, parts.length)); Response jresp = new Response(); jresp.status = "ok"; if (jreq.base64 != null && jreq.base64) jresp.secret = Base64Variants.MIME_NO_LINEFEEDS.encode(secret); else jresp.secret = new String(secret, "UTF-8"); mapper.writeValue(resp.getOutputStream(), jresp); } catch (Throwable t) { t.printStackTrace(); Response jresp = new Response(); jresp.status = "error"; mapper.writeValue(resp.getOutputStream(), jresp); } }