List of usage examples for java.util StringTokenizer hasMoreElements
public boolean hasMoreElements()
From source file:net.sf.jhylafax.fax.HylaFAXClientHelper.java
public final static Document parseFileFmt(String response) { StringTokenizer st = new StringTokenizer(response, QUEUE_SEPARATOR); StringTokenizer jf = new StringTokenizer(FILEFMT, QUEUE_SEPARATOR); Document file = new Document(); while (st.hasMoreElements() && jf.hasMoreElements()) { char c = jf.nextToken().charAt(1); String s = st.nextToken().trim(); if (s.length() > 0) { try { // parse switch (c) { case 'a': file.setLastAccessTime(fileDateFormat.parse(s)); break; case 'c': file.setCreationTime(fileDateFormat.parse(s)); break; case 'd': file.setDeviceNumber(Integer.parseInt(s, 8)); break; case 'f': file.setFilename(s); break; case 'g': file.setGroupID(Integer.parseInt(s)); break; case 'i': file.setInodeNumber(Long.parseLong(s)); break; case 'l': file.setLinkCount(Integer.parseInt(s)); break; case 'm': file.setLastModificationTime(fileDateFormat.parse(s)); break; case 'o': file.setOwner(s);//from w ww.jav a 2 s. c om break; case 'p': // Fax-style protection flags (no group bits) // 'q' is used instead break; case 'q': file.setPermissions(s); break; case 'r': file.setRootDeviceNumber(Integer.parseInt(s)); break; case 's': file.setFilesize(Long.parseLong(s)); break; case 'u': file.setOwnerID(Integer.parseInt(s)); break; } } catch (NumberFormatException e) { logger.info("Error parsing respone", e); } catch (ParseException e) { logger.info("Error parsing response", e); } } } return file; }
From source file:es.eucm.eadandroid.homeapp.repository.resourceHandler.RepoResourceHandler.java
/** * Uncompresses any zip file//from www . j a va2 s . c om */ public static void unzip(String path_from, String path_to, String name, boolean deleteZip) { StringTokenizer separator = new StringTokenizer(name, ".", true); String file_name = separator.nextToken(); File f = new File(path_to + file_name); if (f.exists()) removeDirectory(f); separator = new StringTokenizer(path_to + file_name, "/", true); String partial_path = null; String total_path = separator.nextToken(); while (separator.hasMoreElements()) { partial_path = separator.nextToken(); total_path = total_path + partial_path; if (!new File(total_path).exists()) { if (separator.hasMoreElements()) total_path = total_path + separator.nextToken(); else (new File(total_path)).mkdir(); } else total_path = total_path + separator.nextToken(); } Enumeration<? extends ZipEntry> entries = null; ZipFile zipFile = null; try { String location_ead = path_from + name; zipFile = new ZipFile(location_ead); entries = zipFile.entries(); BufferedOutputStream file; while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); separator = new StringTokenizer(entry.getName(), "/", true); partial_path = null; total_path = ""; while (separator.hasMoreElements()) { partial_path = separator.nextToken(); total_path = total_path + partial_path; if (!new File(entry.getName()).exists()) { if (separator.hasMoreElements()) { total_path = total_path + separator.nextToken(); (new File(path_to + file_name + "/" + total_path)).mkdir(); } else { file = new BufferedOutputStream( new FileOutputStream(path_to + file_name + "/" + total_path)); System.err.println("Extracting file: " + entry.getName()); copyInputStream(zipFile.getInputStream(entry), file); } } else { total_path = total_path + separator.nextToken(); } } } zipFile.close(); } catch (IOException ioe) { ioe.printStackTrace(); return; } if (deleteZip) (new File(path_from + name)).delete(); }
From source file:net.sf.jhylafax.fax.HylaFAXClientHelper.java
public final static ReceivedFax parseRcvFmt(String response) { StringTokenizer st = new StringTokenizer(response, QUEUE_SEPARATOR); StringTokenizer jf = new StringTokenizer(RCVFMT, QUEUE_SEPARATOR); ReceivedFax fax = new ReceivedFax(); while (st.hasMoreElements() && jf.hasMoreElements()) { char c = jf.nextToken().charAt(1); String s = st.nextToken().trim(); if (s.length() > 0) { try { switch (c) { case 'Y': Date date = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").parse(s); fax.setReceivedTime(date); break; case 'a': fax.setSubAddress(s); break; case 'b': fax.setSignallingRate(Integer.parseInt(s)); break; case 'd': fax.setDataFormat(s); break; case 'e': fax.setLastError(s); break; case 'f': fax.setFilename(s);/*from w w w .ja va 2 s. c o m*/ break; case 'h': fax.setTimeSpent(parseDuration(s)); break; case 'i': fax.setCallerIDName(s); break; case 'j': fax.setCallerIDNumber(s); break; case 'l': // FIXME '4294967295' fax.setPageLength(Integer.parseInt(s)); break; case 'm': // Fax-style protection mode string // 'q' is used instead break; case 'n': fax.setFilesize(Long.parseLong(s)); break; case 'o': fax.setOwner(s); break; case 'p': fax.setPageCount(Integer.parseInt(s)); break; case 'q': fax.setProtectionMode(Integer.parseInt(s)); break; case 'r': fax.setResolution(Integer.parseInt(s)); break; case 's': fax.setSender(s); break; case 't': // the handling code never worked correctly // 'Y' is used instead //job.setSendTime(parseDate(s, false)); break; case 'w': fax.setPageWidth(Integer.parseInt(s)); break; case 'z': fax.setReceiving(s.equals("*")); break; } } catch (ParseException e) { logger.info("Error parsing response", e); } catch (NumberFormatException e) { logger.info("Error parsing response", e); } } } return fax; }
From source file:com.redhat.rhn.common.util.StringUtil.java
/** * Convert a string of options (name value pairs separated by '=', where the * pairs are seperated by 'separator'), into a map. * @param options the string of options//from w w w. j a va 2 s .com * @param errorKey the localization key of the error message to throw if we * can't parse it correctly * @param separator the separator the separates different name value pairs * @return a map containing name value pairs of options * @throws ValidatorException if there isn't an '=' sign seperating the * pairs */ public static Map<String, String> convertOptionsToMap(String options, String errorKey, String separator) throws ValidatorException { Map<String, String> toReturn = new HashMap<String, String>(); StringTokenizer token = new StringTokenizer(options, separator); while (token.hasMoreElements()) { String option = token.nextToken(); if (!StringUtils.isBlank(option)) { //Skip blank lines String[] args = option.split("=", 2); if (args.length != 2) { ValidatorException.raiseException(errorKey, option); } else { toReturn.put(args[0], args[1].trim()); } } } return toReturn; }
From source file:marytts.util.string.StringUtils.java
public static String deblank(String str) { StringTokenizer s = new StringTokenizer(str, " ", false); StringBuilder strRet = new StringBuilder(); while (s.hasMoreElements()) strRet.append(s.nextElement());// ww w . j a va 2s . c om return strRet.toString(); }
From source file:com.basho.riak.client.http.util.ClientUtils.java
/** * Extract X-Riak-Index-* headers and create {@link List} of * {@link RiakIndex}es from them//from ww w . j a v a 2 s.co m * * @param headers * The full HTTP headers from the response * @return a List of RiakIndexs */ @SuppressWarnings("rawtypes") public static List<RiakIndex> parseIndexHeaders(Map<String, String> headers) { final List<RiakIndex> indexes = new ArrayList<RiakIndex>(); if (headers != null) { for (Entry<String, String> e : headers.entrySet()) { String header = e.getKey(); if (header != null && header.toLowerCase().startsWith(Constants.HDR_SEC_INDEX_PREFIX)) { String name = header.substring(Constants.HDR_SEC_INDEX_PREFIX.length()); String value = e.getValue(); StringTokenizer st = new StringTokenizer(value, COMMA); if (name.endsWith(BinIndex.SUFFIX)) { while (st.hasMoreTokens()) { indexes.add(new BinIndex(name, st.nextToken().trim())); } } else if (name.endsWith(IntIndex.SUFFIX)) { while (st.hasMoreElements()) { indexes.add(new IntIndex(name, Long.parseLong(st.nextToken().trim()))); } } } } } return indexes; }
From source file:com.microsoftopentechnologies.windowsazurestorage.WAStorageClient.java
/** * Uploads files to Windows Azure Storage. * * @param run environment of build/* ww w .j a va 2s. c om*/ * @param listener logging * @param launcher env vars for remote builds * @param strAcc storage account information. * @param expContainerName container name. * @param cntPubAccess denotes if container is publicly accessible. * @param expFP File Path in ant glob syntax relative to CI tool workspace. * @param expVP Virtual Path of blob container. * @param excludeFP File Path in ant glob syntax to exclude from upload * @param uploadType upload file type * @param individualBlobs blobs from build * @param archiveBlobs blobs from build in archive files * @param cleanUpContainer if container is cleaned * @return filesUploaded number of files that are uploaded. * @throws WAStorageException throws exception */ public static int upload(Run<?, ?> run, Launcher launcher, TaskListener listener, StorageAccountInfo strAcc, String expContainerName, boolean cntPubAccess, boolean cleanUpContainer, String expFP, String expVP, String excludeFP, UploadType uploadType, List<AzureBlob> individualBlobs, List<AzureBlob> archiveBlobs, FilePath workspace) throws WAStorageException { int filesUploaded = 0; // Counter to track no. of files that are uploaded try { FilePath workspacePath = new FilePath(launcher.getChannel(), workspace.getRemote()); listener.getLogger().println(Messages.WAStoragePublisher_uploading()); CloudBlobContainer container = WAStorageClient.getBlobContainerReference(strAcc, expContainerName, true, true, cntPubAccess); // Delete previous contents if cleanup is needed if (cleanUpContainer) { deleteContents(container); } final String zipFolderName = "artifactsArchive"; final String zipName = "archive.zip"; // Make sure we exclude the tempPath from archiving. String excludesWithoutZip = "**/" + zipFolderName + "*/" + zipName; if (excludeFP != null) { excludesWithoutZip = excludeFP + "," + excludesWithoutZip; } String archiveIncludes = ""; StringTokenizer strTokens = new StringTokenizer(expFP, fpSeparator); while (strTokens.hasMoreElements()) { String fileName = strTokens.nextToken(); String embeddedVP = null; if (fileName != null && fileName.contains("::")) { int embVPSepIndex = fileName.indexOf("::"); // Separate fileName and Virtual directory name if (fileName.length() > embVPSepIndex + 1) { embeddedVP = fileName.substring(embVPSepIndex + 2, fileName.length()); if (Utils.isNullOrEmpty(embeddedVP)) { embeddedVP = null; } else if (!embeddedVP.endsWith(Constants.FWD_SLASH)) { embeddedVP = embeddedVP + Constants.FWD_SLASH; } } fileName = fileName.substring(0, embVPSepIndex); } archiveIncludes += "," + fileName; // List all the paths without the zip archives. FilePath[] paths = workspacePath.list(fileName, excludesWithoutZip); filesUploaded += paths.length; URI workspaceURI = workspacePath.toURI(); if (uploadType == UploadType.INVALID) { // no files are uploaded return 0; } if (paths.length != 0 && uploadType != UploadType.ZIP) { for (FilePath src : paths) { // Remove the workspace bit of this path URI srcURI = workspaceURI.relativize(src.toURI()); CloudBlockBlob blob; String srcPrefix = srcURI.getPath(); if (Utils.isNullOrEmpty(expVP) && Utils.isNullOrEmpty(embeddedVP)) { blob = container.getBlockBlobReference(srcPrefix); } else { String prefix = expVP; if (!Utils.isNullOrEmpty(embeddedVP)) { if (Utils.isNullOrEmpty(expVP)) { prefix = embeddedVP; } else { prefix = expVP + embeddedVP; } } blob = container.getBlockBlobReference(prefix + srcPrefix); } String uploadedFileHash = upload(listener, blob, src); individualBlobs.add(new AzureBlob(blob.getName(), blob.getUri().toString().replace("http://", "https://"), uploadedFileHash, src.length())); } } } if (filesUploaded != 0 && (uploadType != UploadType.INDIVIDUAL)) { // Create a temp dir for the upload FilePath tempPath = workspacePath.createTempDir(zipFolderName, null); Glob globScanner = new Glob(archiveIncludes, excludesWithoutZip); FilePath zipPath = tempPath.child(zipName); workspacePath.zip(zipPath.write(), globScanner); // When uploading the zip, do not add in the tempDir to the block // blob reference. String blobURI = zipPath.getName(); if (!Utils.isNullOrEmpty(expVP)) { blobURI = expVP + blobURI; } CloudBlockBlob blob = container.getBlockBlobReference(blobURI); String uploadedFileHash = upload(listener, blob, zipPath); // Make sure to note the new blob as an archive blob, // so that it can be specially marked on the azure storage page. archiveBlobs .add(new AzureBlob(blob.getName(), blob.getUri().toString().replace("http://", "https://"), uploadedFileHash, zipPath.length())); tempPath.deleteRecursive(); } } catch (StorageException | IOException | InterruptedException | URISyntaxException e) { throw new WAStorageException(e.getMessage(), e.getCause()); } return filesUploaded; }
From source file:net.sf.jhylafax.fax.HylaFAXClientHelper.java
public final static FaxJob parseJobFmt(String response) { StringTokenizer st = new StringTokenizer(response, QUEUE_SEPARATOR); StringTokenizer jf = new StringTokenizer(JOBFMT, QUEUE_SEPARATOR); FaxJob job = new FaxJob(); while (st.hasMoreElements() && jf.hasMoreElements()) { char c = jf.nextToken().charAt(1); String s = st.nextToken().trim(); if (s.length() > 0) { try { switch (c) { case 'a': job.setState(getState(s.charAt(0))); break; case 'b': job.setConsecutiveFailedTries(Integer.parseInt(s)); break; case 'c': job.setClientMachineName(s); break; case 'd': job.setDialsAttempted(Integer.parseInt(s)); break; case 'e': job.setNumber(s);/*from w w w.ja v a 2 s.c o m*/ break; case 'f': job.setConsecutiveFailedDials(Integer.parseInt(s)); break; case 'g': job.setGroupID(Integer.parseInt(s)); break; case 'h': job.setPageChopping(getPageChopping(s.charAt(0))); break; case 'i': job.setPriority((new Integer(s)).intValue()); break; case 'j': job.setID((new Integer(s)).intValue()); break; case 'k': job.setKillTime(s); break; case 'l': // FIXME 'any' job.setPageLength(Integer.parseInt(s)); break; case 'm': job.setAssignedModem(s); break; case 'n': job.setNotify(getNotify(s.charAt(0))); break; case 'o': job.setOwner(s); break; case 'p': job.setPagesTransmitted(Integer.parseInt(s)); break; case 'q': job.setRetryTime(parseDuration(s)); break; case 'r': job.setResolution((new Integer(s)).intValue()); break; case 's': job.setLastError(s); break; case 't': job.setTriesAttempted((new Integer(s)).intValue()); break; case 'u': job.setMaxTries((new Integer(s)).intValue()); break; case 'v': job.setClientDialString(s); break; case 'w': job.setPageWidth(Integer.parseInt(s)); break; case 'x': // FIXME 'x/y' job.setMaxDials((new Integer(s)).intValue()); break; case 'z': // the handling code never worked correctly, use // 'Y' instead //Date date = parseDate(s, true); //job.setSendTime(date); break; case 'A': job.setDestinationSubAddress(s); break; case 'B': job.setDestinationPassword(s); break; case 'C': job.setDestinationCompanyName(s); break; case 'D': { StringTokenizer t = new StringTokenizer(s, ":"); job.setDialsAttempted(Integer.parseInt(t.nextToken())); job.setMaxDials(Integer.parseInt(t.nextToken())); break; } case 'E': job.setDesiredSignallingRate(s); break; case 'F': job.setClientDialString(s); break; case 'G': job.setDesiredMinScanline(s); break; case 'H': job.setDesiredDataFormat(s); break; case 'I': job.setClientSchedulingPriority(s); break; case 'J': job.setClientJobTag(s); break; case 'K': job.setDesiredECM(s); break; case 'L': job.setDestinationLocation(s); break; case 'M': job.setNotifyAdress(s); break; case 'N': job.setUsePrivateTagLine("P".equals(s)); break; case 'P': { StringTokenizer t = new StringTokenizer(s, ":"); job.setPagesTransmitted(Integer.parseInt(t.nextToken())); job.setPageCount(Integer.parseInt(t.nextToken())); break; } case 'R': job.setReceiver(s); break; case 'S': job.setSender(s); break; case 'T': // Total # tries/maximum # tries // %t, %u are used instead break; case 'U': job.setChoppingThreshold(Double.parseDouble(s)); break; case 'V': job.setJobDoneOperation(s); break; case 'W': job.setCommunicationIdentifier(s); break; case 'X': job.setJobType(getJobType(s.charAt(0))); break; case 'Y': { Date date = new SimpleDateFormat("yyyy/MM/dd HH.mm.ss").parse(s); job.setSendTime(date); break; } case 'Z': { // should work, but for some reason calculates the // wrong time, so 'Y' is used instead Date date = new Date(Long.parseLong(s)); //job.setSendTime(date); break; } } } catch (ParseException e) { logger.info("Error parsing response", e); } catch (NumberFormatException e) { logger.info("Error parsing response", e); } catch (NoSuchElementException e) { logger.info("Error parsing response", e); } } } return job; }
From source file:org.apache.cloudstack.storage.datastore.util.DateraUtil.java
public static String getValue(String keyToMatch, String url, boolean throwExceptionIfNotFound) { String delimiter1 = ";"; String delimiter2 = "="; StringTokenizer st = new StringTokenizer(url, delimiter1); while (st.hasMoreElements()) { String token = st.nextElement().toString(); int index = token.indexOf(delimiter2); if (index == -1) { throw new CloudRuntimeException("Invalid URL format"); }/*w ww . j a va2s . c om*/ String key = token.substring(0, index); if (key.equalsIgnoreCase(keyToMatch)) { return token.substring(index + delimiter2.length()); } } if (throwExceptionIfNotFound) { throw new CloudRuntimeException("Key not found in URL"); } return null; }
From source file:org.apache.cloudstack.storage.datastore.util.DateraUtil.java
public static String getModifiedUrl(String originalUrl) { StringBuilder sb = new StringBuilder(); String delimiter = ";"; StringTokenizer st = new StringTokenizer(originalUrl, delimiter); while (st.hasMoreElements()) { String token = st.nextElement().toString().toUpperCase(); if (token.startsWith(DateraUtil.MANAGEMENT_VIP.toUpperCase()) || token.startsWith(DateraUtil.STORAGE_VIP.toUpperCase())) { sb.append(token).append(delimiter); }//from w w w .ja v a 2 s . co m } String modifiedUrl = sb.toString(); int lastIndexOf = modifiedUrl.lastIndexOf(delimiter); if (lastIndexOf == (modifiedUrl.length() - delimiter.length())) { return modifiedUrl.substring(0, lastIndexOf); } return modifiedUrl; }