List of usage examples for java.lang StringBuffer setLength
@Override public synchronized void setLength(int newLength)
From source file:com.tremolosecurity.proxy.ConfigSys.java
private void procData(HttpFilterRequest req, HttpFilterResponse resp, UrlHolder holder, boolean isText, InputStream ins, PostProcess proc) throws IOException, Exception { byte[] buffer = new byte[10240]; //InputStream in = entity.getContent(); int len;/*from www. ja v a2 s. c o m*/ if (isText) { BufferedReader in = new BufferedReader(new InputStreamReader(ins)); PrintWriter out = resp.getWriter(); //OutputStream out = resp.getOutputStream(); String line; HttpFilterChain chain = new HttpFilterChainImpl(holder, proc); StringBuffer lineBuff = new StringBuffer(); StringBuffer data = new StringBuffer(); while ((line = in.readLine()) != null) { lineBuff.setLength(0); lineBuff.append(line); if (resp != null) { chain.nextFilterResponseText(req, resp, chain, lineBuff); chain.reload(); } try { out.println(lineBuff.toString()); //out.write(line.getBytes("UTF-8")); //out.write("\n".getBytes("UTF-8")); } catch (Exception e) { //do nothing } //out.flush(); } //out.flush(); //out.close(); } else { //req.setAttribute(ProxySys.TREMOLO_BINARY_DATA, baos.toByteArray()); //InputStream in = entity.getContent(); OutputStream out = resp.getOutputStream(); try { while ((len = ins.read(buffer)) != -1) { try { out.write(buffer, 0, len); out.flush(); } catch (Throwable t) { //ignore write errors } } } catch (ConnectionClosedException e) { logger.warn("Connection closed prematurely", e); } catch (SocketException e) { out.flush(); if (logger.isDebugEnabled()) { logger.debug("Connection closed by remote host", e); } } //out.flush(); //out.close(); } }
From source file:com.xie.javacase.json.XMLTokener.java
/** * Get the text in the CDATA block./* w w w .j a v a2s. c o m*/ * @return The string up to the <code>]]></code>. * @throws org.json.JSONException If the <code>]]></code> is not found. */ public String nextCDATA() throws JSONException { char c; int i; StringBuffer sb = new StringBuffer(); for (;;) { c = next(); if (c == 0) { throw syntaxError("Unclosed CDATA"); } sb.append(c); i = sb.length() - 3; if (i >= 0 && sb.charAt(i) == ']' && sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') { sb.setLength(i); return sb.toString(); } } }
From source file:org.openossad.util.core.row.ValueDataUtil.java
public static Object multiply(ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB) throws OpenDESIGNERValueException { if (dataA == null || dataB == null) return null; if ((metaB.isString() && metaA.isNumeric()) || (metaB.isNumeric() && metaA.isString())) { StringBuffer s; String append = ""; int n;//from w ww .java 2 s .c o m if (metaB.isString()) { s = new StringBuffer(metaB.getString(dataB)); append = metaB.getString(dataB); n = metaA.getInteger(dataA).intValue(); } else { s = new StringBuffer(metaA.getString(dataA)); append = metaA.getString(dataA); n = metaB.getInteger(dataB).intValue(); } if (n == 0) s.setLength(0); else for (int i = 1; i < n; i++) s.append(append); return s.toString(); } switch (metaA.getType()) { case ValueMetaInterface.TYPE_NUMBER: return new Double(metaA.getNumber(dataA).doubleValue() * metaB.getNumber(dataB).doubleValue()); case ValueMetaInterface.TYPE_INTEGER: return new Long(metaA.getInteger(dataA).longValue() * metaB.getInteger(dataB).longValue()); case ValueMetaInterface.TYPE_BIGNUMBER: return metaA.getBigNumber(dataA).multiply(metaB.getBigNumber(dataB)); default: throw new OpenDESIGNERValueException( "The 'multiply' function only works on numeric data optionally multiplying strings."); } }
From source file:com.panet.imeta.core.row.ValueDataUtil.java
public static Object multiply(ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB) throws KettleValueException { if (dataA == null || dataB == null) return null; if ((metaB.isString() && metaA.isNumeric()) || (metaB.isNumeric() && metaA.isString())) { StringBuffer s; String append = ""; int n;/* w w w . ja v a 2s .com*/ if (metaB.isString()) { s = new StringBuffer(metaB.getString(dataB)); append = metaB.getString(dataB); n = metaA.getInteger(dataA).intValue(); } else { s = new StringBuffer(metaA.getString(dataA)); append = metaA.getString(dataA); n = metaB.getInteger(dataB).intValue(); } if (n == 0) s.setLength(0); else for (int i = 1; i < n; i++) s.append(append); return s.toString(); } switch (metaA.getType()) { case ValueMetaInterface.TYPE_NUMBER: return new Double(metaA.getNumber(dataA).doubleValue() * metaB.getNumber(dataB).doubleValue()); case ValueMetaInterface.TYPE_INTEGER: return new Long(metaA.getInteger(dataA).longValue() * metaB.getInteger(dataB).longValue()); case ValueMetaInterface.TYPE_BIGNUMBER: return metaA.getBigNumber(dataA).multiply(metaB.getBigNumber(dataB)); default: throw new KettleValueException( "The 'multiply' function only works on numeric data optionally multiplying strings."); } }
From source file:com.digitalgeneralists.assurance.model.compare.ComparisonEngine.java
private void determineDifferences(File source, File target, Scan scan, IFileComparor comparor, IAssuranceThreadPool threadPool, IScanOptions options, Collection<FileReference> exclusions, IProgressMonitor monitor) {/*from w w w .j av a2s . c om*/ if (monitor != null) { StringBuffer message = new StringBuffer(512); monitor.publish(message.append("Comparing ").append(source.toString()).append(" to ") .append(target.toString())); message.setLength(0); message = null; } if ((source == null) && (target == null)) { StringBuffer message = new StringBuffer(512); logger.info(message.append(source).append(" and ").append(target).append(" are both null.")); message.setLength(0); message = null; } else { // If the source file or target file is in the the global // ignore or exclusion list, just bypass it. // Checking both files in case one is null, in which case // we would have a mismatch. if (((!this.fileIsInGlobalIgnore(source, options)) && (!this.fileIsInGlobalIgnore(target, options))) && ((!this.fileIsInExclusions(source, exclusions)) && (!this.fileIsInExclusions(target, exclusions)))) { // Neither source or target is in the global ignore lists. // Only if both the source and target are not null. // NOTE: This logical condition isn't ideal. It works but // it is still not great in terms of readability. if ((source != null) && (target != null)) { if ((source.isDirectory()) && (!target.isDirectory()) || ((!source.isDirectory()) && (target.isDirectory()))) { ComparisonResult result = new ComparisonResult(source, target, AssuranceResultReason.FILE_DIRECTORY_MISMATCH, comparor); scan.addResult(result); result = null; StringBuffer message = new StringBuffer(512); logger.info(message.append(source).append(" does not match ").append(target)); message.setLength(0); message = null; } else { // Both files are either both simple files or both // directories. boolean sourceIsSymbolicLink = AssuranceUtils.checkIfFileIsSymbolicLink(source); boolean targetIsSymbolicLink = AssuranceUtils.checkIfFileIsSymbolicLink(target); if (sourceIsSymbolicLink && targetIsSymbolicLink) { // Both files are symbolic links. Only compare the paths. if (!(source.getPath().equals(target.getPath()))) { ComparisonResult result = new ComparisonResult(source, target, AssuranceResultReason.COMPARE_FAILED, comparor); scan.addResult(result); result = null; StringBuffer message = new StringBuffer(512); logger.info(message.append(source).append(" does not match ").append(target)); message.setLength(0); message = null; } } else { // Either file could be symbolic links. Check for a mismatch. if ((sourceIsSymbolicLink && !targetIsSymbolicLink) || (!sourceIsSymbolicLink && targetIsSymbolicLink)) { ComparisonResult result = new ComparisonResult(source, target, AssuranceResultReason.SYMBOLIC_LINK_MISMATCH, comparor); scan.addResult(result); result = null; StringBuffer message = new StringBuffer(512); logger.info(message.append(source).append(" does not match ").append(target)); message.setLength(0); message = null; } } if (!sourceIsSymbolicLink && !targetIsSymbolicLink) { // Both files are not symbolic links. if (source.isDirectory()) { // The files are both directories. for (File sourceFile : source.listFiles()) { StringBuilder path = new StringBuilder(512); File targetFile = new File(path.append(target.getPath()).append(File.separator) .append(sourceFile.getName()).toString()); path.setLength(0); path = null; // If the source file or target file is in the the global // ignore or exclusion list, just bypass it. // Checking both files in case one is null, in which case // we would have a mismatch. if (((!this.fileIsInGlobalIgnore(sourceFile, options)) && (!this.fileIsInGlobalIgnore(targetFile, options))) && ((!this.fileIsInExclusions(sourceFile, exclusions)) && (!this.fileIsInExclusions(targetFile, exclusions)))) { if (targetFile.exists()) { threadPool.submit(new ComparisonWorker(this, sourceFile, targetFile, scan, threadPool, options, exclusions, monitor)); } else { ComparisonResult result = new ComparisonResult(sourceFile, targetFile, AssuranceResultReason.TARGET_DOES_NOT_EXIST, comparor); scan.addResult(result); result = null; StringBuffer message = new StringBuffer(512); logger.info(message.append(targetFile).append(" does not exist.")); message.setLength(0); logger.info(message.append(sourceFile).append(" does not match ") .append(targetFile)); message.setLength(0); message = null; } } targetFile = null; } this.identifyTargetItemsNotInSource(source, target, scan, comparor, options, exclusions, monitor); } else { // The files are both simple files. try { boolean includeTimestamps = true; boolean includeAdvancedAttributes = true; ScanDefinition scanDefinition = scan.getScanDef(); if (scanDefinition != null) { includeTimestamps = scanDefinition.getIncludeNonCreationTimestamps(); includeAdvancedAttributes = scanDefinition.getIncludeAdvancedAttributes(); } scanDefinition = null; if (comparor.compare(source, target, includeTimestamps, includeAdvancedAttributes)) { StringBuffer message = new StringBuffer(512); logger.info( message.append(source).append(" is identical to ").append(target)); message.setLength(0); message = null; } else { ComparisonResult result = new ComparisonResult(source, target, AssuranceResultReason.COMPARE_FAILED, comparor); scan.addResult(result); result = null; StringBuffer message = new StringBuffer(512); logger.info( message.append(source).append(" does not match ").append(target)); message.setLength(0); message = null; } } catch (NoSuchAlgorithmException e) { ComparisonResult result = new ComparisonResult(source, target, AssuranceResultReason.UNDETERMINED, comparor); result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); scan.addResult(result); result = null; StringBuffer message = new StringBuffer(512); logger.error(message.append("Error comparing ").append(source).append(" to ") .append(target), e); message.setLength(0); message = null; } catch (IOException e) { ComparisonResult result = new ComparisonResult(source, target, AssuranceResultReason.UNDETERMINED, comparor); result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); scan.addResult(result); result = null; StringBuffer message = new StringBuffer(512); logger.error(message.append("Error comparing ").append(source).append(" to ") .append(target), e); message.setLength(0); message = null; } } } } } else { ComparisonResult result = new ComparisonResult(source, target, AssuranceResultReason.FILE_NULL, comparor); scan.addResult(result); result = null; StringBuffer message = new StringBuffer(512); logger.info(message.append(source).append(" does not match ").append(target)); message.setLength(0); message = null; } } } }
From source file:com.clustercontrol.infra.view.action.EnableInfraModuleAction.java
@Override public Object execute(ExecutionEvent event) throws ExecutionException { this.window = HandlerUtil.getActiveWorkbenchWindow(event); // In case this action has been disposed if (null == this.window || !isEnabled()) { return null; }//from w w w. j a v a 2 s . c o m // ??? this.viewPart = HandlerUtil.getActivePart(event); if (!(viewPart instanceof InfraModuleView)) { return null; } InfraModuleView infraModuleView = null; try { infraModuleView = (InfraModuleView) viewPart.getAdapter(InfraModuleView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (infraModuleView == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = null; if (infraModuleView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) infraModuleView.getComposite().getTableViewer().getSelection(); } StringBuffer strModuleIds = new StringBuffer(); List<String> moduleIds = new ArrayList<>(); if (selection != null) { for (Object object : selection.toList()) { String tmpModuleId = (String) ((ArrayList<?>) object).get(GetInfraModuleTableDefine.MODULE_ID); moduleIds.add(tmpModuleId); strModuleIds.append(tmpModuleId + ", "); } strModuleIds.setLength(strModuleIds.length() - 2); } String managerName = infraModuleView.getComposite().getManagementId(); if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.infra.confirm.action", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.enable.setting"), strModuleIds })) == false) { return null; } InfraEndpointWrapper wrapper = InfraEndpointWrapper .getWrapper(infraModuleView.getComposite().getManagerName()); try { InfraManagementInfo info = wrapper.getInfraManagement(managerName); for (String moduleId : moduleIds) { for (InfraModuleInfo module : info.getModuleList()) { if (module.getModuleId().equals(moduleId)) { module.setValidFlg(true); break; } } } try { wrapper.modifyInfraManagement(info); } catch (InvalidRole_Exception e) { // ??? MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.accesscontrol.16")); return null; } catch (InvalidSetting_Exception | NotifyDuplicate_Exception | HinemosUnknown_Exception | InvalidUserPass_Exception | InfraManagementNotFound_Exception | InfraManagementDuplicate_Exception e) { m_log.debug("execute modifyInfraManagement, " + e.getMessage()); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.infra.action.result", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.enable.setting"), Messages.getString("failed"), strModuleIds })); return null; } } catch (HinemosUnknown_Exception | InvalidRole_Exception | InvalidUserPass_Exception | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) { m_log.debug("execute getInfraManagement, " + e.getMessage()); } MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString("message.infra.action.result", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.enable.setting") + "(" + managerName + ")", Messages.getString("successful"), strModuleIds })); infraModuleView.update(infraModuleView.getComposite().getManagerName(), infraModuleView.getComposite().getManagementId()); return null; }
From source file:com.clustercontrol.infra.view.action.DisableInfraModuleAction.java
@Override public Object execute(ExecutionEvent event) throws ExecutionException { this.window = HandlerUtil.getActiveWorkbenchWindow(event); // In case this action has been disposed if (null == this.window || !isEnabled()) { return null; }/* w w w . j a v a 2s .c om*/ // ??? this.viewPart = HandlerUtil.getActivePart(event); if (!(viewPart instanceof InfraModuleView)) { return null; } InfraModuleView infraModuleView = null; try { infraModuleView = (InfraModuleView) viewPart.getAdapter(InfraModuleView.class); } catch (Exception e) { m_log.info("execute " + e.getMessage()); return null; } if (infraModuleView == null) { m_log.info("execute: view is null"); return null; } StructuredSelection selection = null; if (infraModuleView.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) { selection = (StructuredSelection) infraModuleView.getComposite().getTableViewer().getSelection(); } StringBuffer strModuleIds = new StringBuffer(); List<String> moduleIds = new ArrayList<>(); if (selection != null) { for (Object object : selection.toList()) { String tmpModuleId = (String) ((ArrayList<?>) object).get(GetInfraModuleTableDefine.MODULE_ID); moduleIds.add(tmpModuleId); strModuleIds.append(tmpModuleId + ", "); } strModuleIds.setLength(strModuleIds.length() - 2); } String managerName = infraModuleView.getComposite().getManagerName(); if (MessageDialog.openConfirm(null, Messages.getString("confirmed"), Messages.getString("message.infra.confirm.action", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.disable.setting"), strModuleIds })) == false) { return null; } InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName); try { InfraManagementInfo info = wrapper.getInfraManagement(infraModuleView.getComposite().getManagementId()); for (String moduleId : moduleIds) { for (InfraModuleInfo module : info.getModuleList()) { if (module.getModuleId().equals(moduleId)) { module.setValidFlg(false); break; } } } try { wrapper.modifyInfraManagement(info); } catch (InvalidRole_Exception e) { // ??? MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.accesscontrol.16")); return null; } catch (InvalidSetting_Exception | NotifyDuplicate_Exception | HinemosUnknown_Exception | InvalidUserPass_Exception | InfraManagementNotFound_Exception | InfraManagementDuplicate_Exception e) { m_log.debug("execute modifyInfraManagement, " + e.getMessage()); MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.infra.action.result", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.disable.setting"), Messages.getString("failed"), strModuleIds })); return null; } } catch (InvalidRole_Exception e) { MessageDialog.openError(null, Messages.getString("failed"), Messages.getString("message.accesscontrol.16")); } catch (HinemosUnknown_Exception | InvalidUserPass_Exception | NotifyNotFound_Exception | InfraManagementNotFound_Exception e) { m_log.debug("execute getInfraManagement, " + e.getMessage()); MessageDialog.openError(null, Messages.getString("failed"), HinemosMessage.replace(e.getMessage())); } MessageDialog.openInformation(null, Messages.getString("successful"), Messages.getString("message.infra.action.result", new Object[] { Messages.getString("infra.module.id"), Messages.getString("infra.disable.setting") + "(" + managerName + ")", Messages.getString("successful"), strModuleIds })); infraModuleView.update(infraModuleView.getComposite().getManagerName(), infraModuleView.getComposite().getManagementId()); return null; }
From source file:com.bstek.dorado.core.pkgs.PackageManager.java
private static DependsVersion parseDependsVersion(String text) { DependsVersion dependsVersion = new DependsVersion(); boolean beforeContent = true, afterContent = false, inVersion = false, commaFound = false; StringBuffer version = new StringBuffer(16); char c;/*from w w w . j a va2 s. c o m*/ for (int i = 0, len = text.length(); i < len; i++) { c = text.charAt(i); if (c == ' ') { if (inVersion) { throw new IllegalArgumentException(); } continue; } else if (afterContent) { throw new IllegalArgumentException(); } else if (c == '[' || c == '(') { if (!beforeContent) { throw new IllegalArgumentException(); } beforeContent = false; dependsVersion.setIncludeMinVersion(c == '['); } else if (c == ']' || c == ')') { if (beforeContent) { throw new IllegalArgumentException(); } afterContent = true; dependsVersion.setIncludeMaxVersion(c == ']'); } else if (c == ',') { if (beforeContent || commaFound) { throw new IllegalArgumentException(); } if (version.length() > 0) { String v = trimDependsVersion(version.toString()); dependsVersion.setMinVersion(v); version.setLength(0); } } else if (c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'A' || c == '.' || c == '-' || c == '*') { version.append(c); } else { throw new IllegalArgumentException(); } } if (version.length() > 0) { String v = trimDependsVersion(version.toString()); if (commaFound) { dependsVersion.setMaxVersion(v); } else { dependsVersion.setMinVersion(v); dependsVersion.setMaxVersion(v); } } return dependsVersion; }
From source file:com.pureinfo.dolphin.mapping.EntityRelative.java
/** * @see java.lang.Object#toString()//from w w w. j a v a 2s . c om */ public String toString() { StringBuffer sbuff = new StringBuffer(); try { sbuff.append("alias=").append(m_sAlias); sbuff.append(", type=").append(m_sType); sbuff.append(", join-condition=").append(m_sJoinCondition); if (m_depends != null) { sbuff.append(", depends=").append(StringUtils.join(m_depends, ',')); } return sbuff.toString(); } finally { sbuff.setLength(0); } }
From source file:org.jboss.test.classloader.test.ScopingUnitTestCase.java
/** Tests for accessing java system classes from scoped * repositories./*from www .j a v a 2s. c o m*/ * * @throws Exception */ public void testSystemClasses() throws Exception { log.info("+++ Begin testSystemClasses"); UnifiedLoaderRepository3 parent = new UnifiedLoaderRepository3(); HeirarchicalLoaderRepository3 repository0 = new HeirarchicalLoaderRepository3(parent); URL j0URL = getDeployURL("tests-dummy.jar"); RepositoryClassLoader ucl0 = repository0.newClassLoader(j0URL, true); Class c0 = ucl0.loadClass("java.sql.SQLException"); StringBuffer info = new StringBuffer(); ClassLoaderUtils.displayClassInfo(c0, info); log.info("Loaded c0: " + info); HeirarchicalLoaderRepository3 repository1 = new HeirarchicalLoaderRepository3(parent); repository1.setUseParentFirst(false); RepositoryClassLoader ucl1 = repository1.newClassLoader(j0URL, true); Class c1 = ucl1.loadClass("java.sql.SQLException"); info.setLength(0); ClassLoaderUtils.displayClassInfo(c1, info); log.info("Loaded c1: " + info); Class c2 = ucl1.loadClass("java.sql.SQLWarning"); info.setLength(0); ClassLoaderUtils.displayClassInfo(c2, info); log.info("Loaded c2: " + info); }