private String makeStringSize(String str, int nSize) { if ( str.length() >= nSize ) return str.substring(0, nSize); else { String res = ""; for( int i = 0; i < nSize - str.length(); i++ ) res += ' '; res += str; return res; } }
public void checkSecurityAccess(String target) { if (null == target) throw new java.lang.NullPointerException(); if (0 == target.length()) throw new IllegalArgumentException(); // Here can be some security checks and if it fails, throw a new SecurityException }
static public String getRelativePath(String path1, String path2) { if (!path1.startsWith(path2)) return path1; return path1.substring(path2.length()); }
public void writeString(String data) { if (!isOpened()) return; m_st.Write(new UTF8Encoding().GetBytes(data), 0, data.length()); }
public static String urlEncode(String fullPath) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); int len = fullPath.length(); char c; for (int index = 0; index < len; index++) { c = fullPath.charAt(index); if (c == '^' || c == '_' || c == '\\' || c == '-' || c == '.' || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) { sb.Append(c); } else { sb.Append('%'); sb.Append(String.Format("{0:X2}", (int)c)); } } return sb.ToString(); }
public void cancelRequest(String szCallback) { if (szCallback == null || szCallback.length() == 0 ) { LOG.INFO("Cancel callback should not be empty. Use * for cancel all"); return; } lock(getCommandLock()) { HttpCommand pCmd = (HttpCommand)getCurCommand(); if ( pCmd != null && ( szCallback.compareTo("*") == 0 || pCmd.m_strCallback.compareTo(szCallback) == 0) ) pCmd.cancel(); if ( szCallback.compareTo("*") == 0 ) getCommands().Clear(); else { for (int i = getCommands().size()-1; i >= 0; i--) { HttpCommand pCmd1 = (HttpCommand)getCommands().get(i); if ( pCmd1 != null && pCmd1.m_strCallback.compareTo(szCallback) == 0 ) getCommands().RemoveAt(i); } } } }
/** * Returns whether the given source string ends with the suffix, ignoring * case and assuming that the strings are ascii encoded. * * @param source * the string to match. * @param suffix * the suffix to test. * @return {@code true} if the source does end with the given suffix, or * {@code false} if not. */ public static bool asciiEndsWithIgnoreCase(String source, String suffix) { int length = suffix.length(); if (length > source.length()) { return false; } int offset = source.length() - length; for (int i = 0; i < length; i++) { char c1 = source.charAt(i + offset); char c2 = suffix.charAt(i); if (c1 != c2 && toASCIIUpperCase(c1) != toASCIIUpperCase(c2)) { return false; } } return true; }
/** * Construct a new {@code StringBufferInputStream} with {@code str} as * source. The size of the stream is set to the {@code length()} of the * string. * * @param str * the source string for this stream. * @throws NullPointerException * if {@code str} is {@code null}. */ public StringBufferInputStream(String str) { if (str == null) { throw new java.lang.NullPointerException (); } buffer = str; count = str.length (); }
public SyncNotification(String strUrl, String strParams, boolean bRemoveAfterFire) { if ( strUrl.length() > 0 ) m_strUrl = RHODESAPP().canonicalizeRhoUrl(strUrl); m_strParams = strParams; m_bRemoveAfterFire = bRemoveAfterFire; }
/** * Wrap an existing exception in a TransformerException. * * <p>This is used for throwing processor exceptions before * the processing has started.</p> * * @param message The error or warning message, or null to * use the message from the embedded exception. * @param e Any exception */ public TransformerException(String message, java.lang.Throwable e) : base(((message == null) || (message.length() == 0)) ? e.toString() : message) { this.containedException = e; this.locator = null; }
public String getString(String szName, String szDefValue) { Object value = findHashParam(szName); String strRes = value != null ? value.ToString() : ""; if (strRes.length() == 0 && szDefValue != null && szDefValue.length() > 0) strRes = szDefValue; return strRes; }
/** * Creates a new invitation. * * @param invitee the XMPP address of the invitee. The room will forward the invitation to this * address. * @param reason the reason why the invitation is being sent. */ public Invitation(String invitee, String reason) { super(); Element element = addChildElement("x", "http://jabber.org/protocol/muc#user"); Element invite = element.addElement("invite"); invite.addAttribute("to", invitee); if (reason != null && reason.length() > 0) { invite.addElement("reason").setText(reason); } }
public String getServerQueryBody(String strSrcName, String strClientID, int nPageSize) { String strQuery = "?client_id=" + strClientID + "&p_size=" + nPageSize + "&version=3"; if (strSrcName.length() > 0) strQuery += "&source_name=" + strSrcName; return strQuery; }
public String getServerQueryUrl(String strAction) { String strUrl = RhoConf.getInstance().getPath("syncserver"); if (strAction.length() > 0) strUrl = CFilePath.join(strUrl, strAction); else strUrl = strUrl.substring(0, strUrl.length() - 1); return strUrl; }
/** * Constructs a new {@code ZipEntry} with the specified name. * * @param name * the name of the ZIP entry. * @throws IllegalArgumentException * if the name length is outside the range (> 0xFFFF). */ public ZipEntry(String name) { if (name == null) { throw new java.lang.NullPointerException(); } if (name.length() > 0xFFFF) { throw new java.lang.IllegalArgumentException(); } this.name = name; }
public CAttrValue(String strAttrib, String strValue) { m_strAttrib = strAttrib; m_strValue = strValue; if ( m_strAttrib.endsWith("-rhoblob") ) { m_strBlobSuffix = "-rhoblob"; m_strAttrib = m_strAttrib.substring(0,m_strAttrib.length()-m_strBlobSuffix.length()); } }
/** * Constructs a new {@code StringCharacterIterator} on the specified string * with the current index set to the specified value. The begin index is set * to the beginning of the string, the end index is set to the length of the * string. * * @param value * the source string to iterate over. * @param location * the current index. * @throws IllegalArgumentException * if {@code location} is negative or greater than the length * of the source string. */ public StringCharacterIterator(String value, int location) { stringJ = value; start = 0; end = stringJ.length(); if (location < 0 || location > end) { throw new java.lang.IllegalArgumentException(); } offset = location; }
public static String changeBaseName( String path, String szFileName ) { int basePos = findLastSlash(path); if (basePos >= 0 && basePos < path.length() - 1) { String res = path.substring(0, basePos + 1); res += szFileName; return res; } return join(path, szFileName); }
/** * Canonicalize the path, i.e. remove ".." and "." occurences. * * @param path the path to be canonicalized * @return the canonicalized path */ public static String canonicalizePath(String path) { int dirIndex; while ((dirIndex = path.indexOf("/./")) >= 0) { //$NON-NLS-1$ path = path.substring(0, dirIndex + 1) + path.substring(dirIndex + 3); } if (path.endsWith("/.")) { //$NON-NLS-1$ path = path.substring(0, path.length() - 1); } while ((dirIndex = path.indexOf("/../")) >= 0) { //$NON-NLS-1$ if (dirIndex != 0) { path = path.substring(0, path .lastIndexOf('/', dirIndex - 1)) + path.substring(dirIndex + 3); } else { path = path.substring(dirIndex + 3); } } if (path.endsWith("/..") && path.length() > 3) { //$NON-NLS-1$ path = path.substring(0, path.lastIndexOf('/', path.length() - 4) + 1); } return path; }
public static String toASCIIUpperCase(String s) { int len = s.length(); StringBuilder buffer = new StringBuilder(len); for (int i = 0; i < len; i++) { char c = s.charAt(i); if ('a' <= c && c <= 'z') { buffer.append((char)(c - ('a' - 'A'))); } else { buffer.append(c); } } return buffer.toString(); }
/** * Parses <code>source</code> until a non-whitespace character is found. * * @param source the string to parse * @param pos input/ouput parsing parameter. * @return the first non-whitespace character. */ public static char parseNextCharacter(String source, ParsePosition pos) { int index = pos.getIndex(); int n = source.length(); char ret = 0; if (index < n) { char c; do { c = source.charAt(index++); } while (Character.isWhitespace(c) && index < n); pos.setIndex(index); if (index < n) { ret = c; } } return ret; }
public PropertyDescriptor(String propertyName, java.lang.Class beanClass, String getterName, String setterName) : base() { //throws IntrospectionException { if (beanClass == null) { throw new IntrospectionException("Target Bean class is null");//Messages.getString("beans.03")); //$NON-NLS-1$ } if (propertyName == null || propertyName.length() == 0) { throw new IntrospectionException("bad property name");//Messages.getString("beans.04")); //$NON-NLS-1$ } this.setName(propertyName); if (getterName != null) { if (getterName.length() == 0) { throw new IntrospectionException( "read or write method cannot be empty."); //$NON-NLS-1$ } try { setReadMethod(beanClass, getterName); } catch (IntrospectionException e) { setReadMethod(beanClass, createDefaultMethodName(propertyName, "get")); //$NON-NLS-1$ } } if (setterName != null) { if (setterName.length() == 0) { throw new IntrospectionException( "read or write method cannot be empty."); //$NON-NLS-1$ } setWriteMethod(beanClass, setterName); } }
public void writeLogMessage(String strMsg) { try{ int len = strMsg.length(); if ( m_pFile == null ) m_pFile = new CRhoFile(); if ( !m_pFile.isOpened() ){ m_pFile.open( getLogConf().getLogFilePath(), CRhoFile.EOpenModes.OpenForAppend ); m_nFileLogSize = (int)m_pFile.size(); loadLogPosition(); } if ( getLogConf().getMaxLogFileSize() > 0 ) { if ( ( m_nCirclePos >= 0 && m_nCirclePos + len > getLogConf().getMaxLogFileSize() ) || ( m_nCirclePos < 0 && m_nFileLogSize + len > getLogConf().getMaxLogFileSize() ) ) { m_pFile.movePosToStart(); m_nFileLogSize = 0; m_nCirclePos = 0; } } //int nWritten = m_pFile.writeString(strMsg); m_pFile.writeString(strMsg); m_pFile.flush(); if ( m_nCirclePos >= 0 ) m_nCirclePos += len; else m_nFileLogSize += len; saveLogPosition(); }catch(Exception exc){ log(exc.Message); } }
internal const String encoding = "utf-8"; //$NON-NLS-1$ #endregion Fields #region Methods /** * All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9') * and legal characters are converted into their hexidecimal value prepended * by '%'. * <p> * For example: '#' -> %23 * Other characters, which are unicode chars that are not US-ASCII, and are * not ISO Control or are not ISO Space chars, are preserved. * <p> * Called from {@code URI.quoteComponent()} (for multiple argument * constructors) * * @param s * java.lang.String the string to be converted * @param legal * java.lang.String the characters allowed to be preserved in the * string s * @return java.lang.String the converted string */ internal static String quoteIllegal(String s, String legal) { //throws UnsupportedEncodingException { StringBuilder buf = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || legal.indexOf(ch) > -1 || (ch > 127 && !java.lang.Character.isSpaceChar(ch) && !java.lang.Character .isISOControl(ch))) { buf.append(ch); } else { byte[] bytes = new String(new char[] { ch }).getBytes(encoding); for (int j = 0; j < bytes.Length; j++) { buf.append('%'); buf.append(digits.charAt((bytes[j] & 0xf0) >> 4)); buf.append(digits.charAt(bytes[j] & 0xf)); } } } return buf.toString(); }
/** * Decapitalizes a given string according to the rule: * <ul> * <li>If the first or only character is Upper Case, it is made Lower Case * <li>UNLESS the second character is also Upper Case, when the String is * returned unchanged <eul> * * @param name - * the String to decapitalize * @return the decapitalized version of the String */ public static String decapitalize(String name) { if (name == null) return null; // The rule for decapitalize is that: // If the first letter of the string is Upper Case, make it lower case // UNLESS the second letter of the string is also Upper Case, in which case no // changes are made. if (name.length() == 0 || (name.length() > 1 && java.lang.Character.isUpperCase(name.charAt(1)))) { return name; } char[] chars = name.toCharArray(); chars[0] = java.lang.Character.toLowerCase(chars[0]); return new String(chars); }
/** * Creates a new URL to the specified resource {@code spec}. This URL is * relative to the given {@code context}. The {@code handler} will be used * to parse the URL string representation. If this argument is {@code null} * the default {@code URLStreamHandler} will be used. If the protocol of the * parsed URL does not match with the protocol of the context URL, then the * newly created URL is absolute and bases only on the given URL represented * by {@code spec}. Otherwise the protocol is defined by the context URL. * * @param context * the URL which is used as the context. * @param spec * the URL string representation which has to be parsed. * @param handler * the specific stream handler to be used by this URL. * @throws MalformedURLException * if the given string {@code spec} could not be parsed as a URL * or an invalid protocol has been found. */ public URL(URL context, String spec, URLStreamHandler handler) { //throws MalformedURLException { if (handler != null) { java.lang.SecurityManager sm = java.lang.SystemJ.getSecurityManager(); if (sm != null) { sm.checkPermission(specifyStreamHandlerPermission); } strmHandler = handler; } if (spec == null) { throw new MalformedURLException(); } spec = spec.trim(); // The spec includes a protocol if it includes a colon character // before the first occurrence of a slash character. Note that, // "protocol" is the field which holds this URLs protocol. int index; try { index = spec.indexOf(':'); } catch (java.lang.NullPointerException e) { throw new MalformedURLException(e.toString()); } int startIPv6Addr = spec.indexOf('['); if (index >= 0) { if ((startIPv6Addr == -1) || (index < startIPv6Addr)) { protocol = spec.substring(0, index); // According to RFC 2396 scheme part should match // the following expression: // alpha *( alpha | digit | "+" | "-" | "." ) char c = protocol.charAt(0); bool valid = ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); for (int i = 1; valid && (i < protocol.length()); i++) { c = protocol.charAt(i); valid = ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || (c == '+') || (c == '-') || (c == '.'); } if (!valid) { protocol = null; index = -1; } else { // Ignore case in protocol names. // Scheme is defined by ASCII characters. protocol = Util.toASCIILowerCase(protocol); } } } if (protocol != null) { // If the context was specified, and it had the same protocol // as the spec, then fill in the receiver's slots from the values // in the context but still allow them to be over-ridden later // by the values in the spec. if (context != null && protocol.equals(context.getProtocol())) { String cPath = context.getPath(); if (cPath != null && cPath.startsWith("/")) { //$NON-NLS-1$ set(protocol, context.getHost(), context.getPort(), context .getAuthority(), context.getUserInfo(), cPath, context.getQuery(), null); } if (strmHandler == null) { strmHandler = context.strmHandler; } } } else { // If the spec did not include a protocol, then the context // *must* be specified. Fill in the receiver's slots from the // values in the context, but still allow them to be over-ridden // by the values in the ("relative") spec. if (context == null) { throw new MalformedURLException("Protocol not found: " + spec); //$NON-NLS-1$ } set(context.getProtocol(), context.getHost(), context.getPort(), context.getAuthority(), context.getUserInfo(), context .getPath(), context.getQuery(), null); if (strmHandler == null) { strmHandler = context.strmHandler; } } // If the stream handler has not been determined, set it // to the default for the specified protocol. if (strmHandler == null) { setupStreamHandler(); if (strmHandler == null) { throw new MalformedURLException("Unknown protocol: " + protocol); //$NON-NLS-1$ } } // Let the handler parse the URL. If the handler throws // any exception, throw MalformedURLException instead. // // Note: We want "index" to be the index of the start of the scheme // specific part of the URL. At this point, it will be either // -1 or the index of the colon after the protocol, so we // increment it to point at either character 0 or the character // after the colon. try { strmHandler.parseURL(this, spec, ++index, spec.length()); } catch (Exception e) { throw new MalformedURLException(e.toString()); } if (port < -1) { throw new MalformedURLException("Port out of range: " + port); //$NON-NLS-1$ } }
private void validateName(String name) { if (name.endsWith("/") && name.length() > 1) { //$NON-NLS-1$ // prefs.6=Name cannot end with '/' throw new java.lang.IllegalArgumentException("Name cannot end with '/'"); //$NON-NLS-1$ } if (name.indexOf("//") >= 0) { //$NON-NLS-1$ // prefs.7=Name cannot contains consecutive '/' throw new java.lang.IllegalArgumentException("Name cannot contains consecutive '/'"); //$NON-NLS-1$ } }
private AbstractPreferences getNodeFromBackend(bool createNew, AbstractPreferences currentNode, String name) { //throws BackingStoreException { if (name.length() > MAX_NAME_LENGTH) { // prefs.8=Name length is too long: {0} throw new java.lang.IllegalArgumentException("Name length is too long: "+ name); } AbstractPreferences temp; if (createNew) { temp = currentNode.childSpi(name); currentNode.cachedNode.put(name, temp); if (temp.newNode && currentNode.nodeChangeListeners.size() > 0) { currentNode.notifyChildAdded(temp); } } else { temp = currentNode.getChild(name); } return temp; }
public override void put(String key, String value) { if (null == key || null == value) { throw new java.lang.NullPointerException(); } if (key.length() > MAX_KEY_LENGTH || value.length() > MAX_VALUE_LENGTH) { throw new java.lang.IllegalArgumentException(); } lock (lockJ) { checkState(); putSpi(key, value); } notifyPreferenceChange(key, value); }
/* * ----------------------------------------------------------- Constructors * ----------------------------------------------------------- */ /** * Constructs a new {@code AbstractPreferences} instance using the given * parent node and node name. * * @param parent * the parent node of the new node or {@code null} to indicate * that the new node is a root node. * @param name * the name of the new node or an empty string to indicate that * this node is called "root". * @throws IllegalArgumentException * if the name contains a slash character or is empty if {@code * parent} is not {@code null}. */ protected AbstractPreferences(AbstractPreferences parent, String name) { if ((null == parent ^ name.length() == 0) || name.indexOf("/") >= 0) { //$NON-NLS-1$ throw new java.lang.IllegalArgumentException(); } root = null == parent ? this : parent.root; nodeChangeListeners = new LinkedList<EventListener>(); preferenceChangeListeners = new LinkedList<EventListener>(); isRemovedJ = false; cachedNode = new HashMap<String, AbstractPreferences>(); nodeName = name; parentPref = parent; lockJ = new Lock(); userNode = root.userNode; }