code
stringlengths
73
34.1k
label
stringclasses
1 value
public static MergeResult mergeRevision(long revision, File directory, String branch, String baseUrl) throws IOException { // svn merge -r 1288:1351 http://svn.example.com/myrepos/branch CommandLine cmdLine = new CommandLine(SVN_CMD); cmdLine.addArgument(CMD_MERGE); addDefaultArguments(c...
java
public static String getMergedRevisions(File directory, String... branches) throws IOException { // we could also use svn mergeinfo --show-revs merged ^/trunk ^/branches/test CommandLine cmdLine; cmdLine = new CommandLine(SVN_CMD); cmdLine.addArgument("propget"); addDefaultArgume...
java
public static void revertAll(File directory) throws IOException { log.info("Reverting SVN Working copy at " + directory); CommandLine cmdLine = new CommandLine(SVN_CMD); cmdLine.addArgument(CMD_REVERT); addDefaultArguments(cmdLine, null, null); cmdLine.addArgument(OPT_DEPTH); ...
java
public static void cleanup(File directory) throws IOException { log.info("Cleaning SVN Working copy at " + directory); CommandLine cmdLine = new CommandLine(SVN_CMD); cmdLine.addArgument("cleanup"); addDefaultArguments(cmdLine, null, null); try (InputStream result = ExecutionHe...
java
public static InputStream checkout(String url, File directory, String user, String pwd) throws IOException { if (!directory.exists() && !directory.mkdirs()) { throw new IOException("Could not create new working copy directory at " + directory); } CommandLine cmdLine = new CommandLin...
java
public static void copyBranch(String base, String branch, long revision, String baseUrl) throws IOException { log.info("Copying branch " + base + AT_REVISION + revision + " to branch " + branch); CommandLine cmdLine = new CommandLine(SVN_CMD); cmdLine.addArgument("cp"); addDefaultArgume...
java
public ConfigurationStore getStore() throws ConfigException { if (store != null) { return store; } String uriStr = getConfigUri(); if (uriStr == null) { getPfile(); String configPname = getConfigPname(); if (configPname == null) { throw new ConfigException("Either a u...
java
protected String loadOnlyConfig(final Class<T> cl) { try { /* Load up the config */ ConfigurationStore cs = getStore(); List<String> configNames = cs.getConfigs(); if (configNames.isEmpty()) { error("No configuration on path " + cs.getLocation()); return "No configuration ...
java
public static StorageConfiguration deserialize(final File pFile) throws TTIOException { try { FileReader fileReader = new FileReader(new File(pFile, Paths.ConfigBinary.getFile().getName())); JsonReader jsonReader = new JsonReader(fileReader); jsonReader.beginObject(); ...
java
@ConfInfo(dontSave = true) public String getProperty(final Collection<String> col, final String name) { String key = name + "="; for (String p: col) { if (p.startsWith(key)) { return p.substring(key.length()); } } return null; }
java
public void removeProperty(final Collection<String> col, final String name) { try { String v = getProperty(col, name); if (v == null) { return; } col.remove(name + "=" + v); } catch (Throwable t) { throw new RuntimeException(t); } }
java
@SuppressWarnings("unchecked") public <L extends List> L setListProperty(final L list, final String name, final String val) { removeProperty(list, name); return addListProperty(list, name, val); }
java
public void toXml(final Writer wtr) throws ConfigException { try { XmlEmit xml = new XmlEmit(); xml.addNs(new NameSpace(ns, "BW"), true); xml.startEmit(wtr); dump(xml, false); xml.flush(); } catch (ConfigException cfe) { throw cfe; } catch (Throwable t) { throw new...
java
public ConfigBase fromXml(final InputStream is, final Class cl) throws ConfigException { try { return fromXml(parseXml(is), cl); } catch (final ConfigException ce) { throw ce; } catch (final Throwable t) { throw new ConfigException(t); } }
java
public ConfigBase fromXml(final Element rootEl, final Class cl) throws ConfigException { try { final ConfigBase cb = (ConfigBase)getObject(rootEl, cl); if (cb == null) { // Can't do this return null; } for (final Element el: XmlUtil.getElementsAr...
java
public void setPath(final String ideal, final String actual) { synchronized (transformers) { pathMap.put(ideal, actual); } }
java
public static void initLogging() throws IOException { sendCommonsLogToJDKLog(); try (InputStream resource = Thread.currentThread().getContextClassLoader().getResourceAsStream("logging.properties")) { // apply configuration if(resource != null) { try { LogManager.getLogManager().readConfiguration(res...
java
public void add(final ITreeData paramNodeX, final ITreeData paramNodeY) throws TTIOException { mMapping.put(paramNodeX, paramNodeY); mReverseMapping.put(paramNodeY, paramNodeX); updateSubtreeMap(paramNodeX, mRtxNew); updateSubtreeMap(paramNodeY, mRtxOld); }
java
public long containedChildren(final ITreeData paramNodeX, final ITreeData paramNodeY) throws TTIOException { assert paramNodeX != null; assert paramNodeY != null; long retVal = 0; mRtxOld.moveTo(paramNodeX.getDataKey()); for (final AbsAxis axis = new DescendantAxis(mRtxOld, true...
java
public static List<String> fixPath(final String path) throws ServletException { if (path == null) { return null; } String decoded; try { decoded = URLDecoder.decode(path, "UTF8"); } catch (Throwable t) { throw new ServletException("bad path: " + path); } if (decoded == nu...
java
protected Object readJson(final InputStream is, final Class cl, final HttpServletResponse resp) throws ServletException { if (is == null) { return null; } try { return getMapper().readValue(is, cl); } catch (Throwable t) { resp.s...
java
public static String timeToReadable(long millis, String suffix) { StringBuilder builder = new StringBuilder(); boolean haveDays = false; if(millis > ONE_DAY) { millis = handleTime(builder, millis, ONE_DAY, "day", "s"); haveDays = true; } boolean haveHours...
java
public static synchronized XMLEventReader createFileReader(final File paramFile) throws IOException, XMLStreamException { final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.SUPPORT_DTD, false); final InputStream in = new FileInputStream(par...
java
public static synchronized XMLEventReader createStringReader(final String paramString) throws IOException, XMLStreamException { final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.SUPPORT_DTD, false); final InputStream in = new ByteArrayInpu...
java
public String simpleGet(String url) throws IOException { final AtomicReference<String> str = new AtomicReference<>(); simpleGetInternal(url, inputStream -> { try { str.set(IOUtils.toString(inputStream, "UTF-8")); } catch (IOException e) { throw new IllegalStat...
java
public byte[] simpleGetBytes(String url) throws IOException { final AtomicReference<byte[]> bytes = new AtomicReference<>(); simpleGetInternal(url, inputStream -> { try { bytes.set(IOUtils.toByteArray(inputStream)); } catch (IOException e) { throw new IllegalS...
java
public void simpleGet(String url, Consumer<InputStream> consumer) throws IOException { simpleGetInternal(url, consumer, null); }
java
public static String retrieveData(String url, String user, String password, int timeoutMs) throws IOException { try (HttpClientWrapper wrapper = new HttpClientWrapper(user, password, timeoutMs)) { return wrapper.simpleGet(url); } }
java
public static HttpEntity checkAndFetch(HttpResponse response, String url) throws IOException { int statusCode = response.getStatusLine().getStatusCode(); if(statusCode > 206) { String msg = "Had HTTP StatusCode " + statusCode + " for request: " + url + ", response: " + response.getStatusLine().g...
java
public void createResource(final InputStream inputStream, final String resourceName) throws JaxRxException { synchronized (resourceName) { if (inputStream == null) { throw new JaxRxException(400, "Bad user request"); } else { try { ...
java
public void add(final InputStream input, final String resource) throws JaxRxException { synchronized (resource) { try { shred(input, resource); } catch (final TTException exce) { throw new JaxRxException(exce); } } }
java
public void deleteResource(final String resourceName) throws WebApplicationException { synchronized (resourceName) { try { mDatabase.truncateResource(new SessionConfiguration(resourceName, null)); } catch (TTException e) { throw new WebApplicationException...
java
public long getLastRevision(final String resourceName) throws JaxRxException, TTException { long lastRevision; if (mDatabase.existsResource(resourceName)) { ISession session = null; try { session = mDatabase.getSession(new SessionConfiguration(resourceName, Stand...
java
private void serializIt(final String resource, final Long revision, final OutputStream output, final boolean nodeid) throws JaxRxException, TTException { // Connection to treetank, creating a session ISession session = null; // INodeReadTrx rtx = null; try { session =...
java
public void revertToRevision(final String resourceName, final long backToRevision) throws JaxRxException, TTException { ISession session = null; INodeWriteTrx wtx = null; boolean abort = false; try { session = mDatabase.getSession(new SessionConfiguration(resourceName...
java
private String discover(final String url) throws TimezonesException { /* For the moment we'll try to find it via .well-known. We may have to * use DNS SRV lookups */ // String domain = hi.getHostname(); // int lpos = domain.lastIndexOf("."); //int lpos2 = domain.lastIndexOf(".", lpos - 1); // ...
java
@Override protected void emitEndElement(final INodeReadTrx paramRTX) { try { indent(); mOut.write(ECharsForSerializing.OPEN_SLASH.getBytes()); mOut.write(paramRTX.nameForKey(((ITreeNameData)paramRTX.getNode()).getNameKey()).getBytes()); mOut.write(ECharsForSer...
java
private void indent() throws IOException { if (mIndent) { for (int i = 0; i < mStack.size() * mIndentSpaces; i++) { mOut.write(" ".getBytes()); } } }
java
private void write(final long mValue) throws IOException { final int length = (int)Math.log10((double)mValue); int digit = 0; long remainder = mValue; for (int i = length; i >= 0; i--) { digit = (byte)(remainder / LONG_POWERS[i]); mOut.write((byte)(digit + ASCII_O...
java
public static String isoDate(final Date val) { synchronized (isoDateFormat) { try { isoDateFormat.setTimeZone(Timezones.getDefaultTz()); } catch (TimezonesException tze) { throw new RuntimeException(tze); } return isoDateFormat.format(val); } }
java
public static String rfcDate(final Date val) { synchronized (rfcDateFormat) { try { rfcDateFormat.setTimeZone(Timezones.getDefaultTz()); } catch (TimezonesException tze) { throw new RuntimeException(tze); } return rfcDateFormat.format(val); } }
java
public static String isoDateTime(final Date val) { synchronized (isoDateTimeFormat) { try { isoDateTimeFormat.setTimeZone(Timezones.getDefaultTz()); } catch (TimezonesException tze) { throw new RuntimeException(tze); } return isoDateTimeFormat.format(val); } }
java
public static String isoDateTime(final Date val, final TimeZone tz) { synchronized (isoDateTimeTZFormat) { isoDateTimeTZFormat.setTimeZone(tz); return isoDateTimeTZFormat.format(val); } }
java
public static Date fromISODate(final String val) throws BadDateException { try { synchronized (isoDateFormat) { try { isoDateFormat.setTimeZone(Timezones.getDefaultTz()); } catch (TimezonesException tze) { throw new RuntimeException(tze); } return isoDateFor...
java
public static Date fromRfcDate(final String val) throws BadDateException { try { synchronized (rfcDateFormat) { try { rfcDateFormat.setTimeZone(Timezones.getDefaultTz()); } catch (TimezonesException tze) { throw new RuntimeException(tze); } return rfcDateFor...
java
public static Date fromISODateTime(final String val) throws BadDateException { try { synchronized (isoDateTimeFormat) { try { isoDateTimeFormat.setTimeZone(Timezones.getDefaultTz()); } catch (TimezonesException tze) { throw new RuntimeException(tze); } retur...
java
public static Date fromISODateTime(final String val, final TimeZone tz) throws BadDateException { try { synchronized (isoDateTimeTZFormat) { isoDateTimeTZFormat.setTimeZone(tz); return isoDateTimeTZFormat.parse(val); } } catch (Throwable t) { ...
java
@SuppressWarnings("unused") public static Date fromISODateTimeUTC(final String val, final TimeZone tz) throws BadDateException { try { synchronized (isoDateTimeUTCTZFormat) { isoDateTimeUTCTZFormat.setTimeZone(tz); return isoDateTimeUTCTZFormat.parse(v...
java
public static Date fromISODateTimeUTC(final String val) throws BadDateException { try { synchronized (isoDateTimeUTCFormat) { return isoDateTimeUTCFormat.parse(val); } } catch (Throwable t) { throw new BadDateException(); } }
java
public static String fromISODateTimeUTCtoRfc822(final String val) throws BadDateException { try { synchronized (isoDateTimeUTCFormat) { return rfc822Date(isoDateTimeUTCFormat.parse(val)); } } catch (Throwable t) { throw new BadDateException(); } }
java
public static boolean isISODate(final String val) throws BadDateException { try { if (val.length() != 8) { return false; } fromISODate(val); return true; } catch (Throwable t) { return false; } }
java
public static boolean isISODateTimeUTC(final String val) throws BadDateException { try { if (val.length() != 16) { return false; } fromISODateTimeUTC(val); return true; } catch (Throwable t) { return false; } }
java
public static boolean isISODateTime(final String val) throws BadDateException { try { if (val.length() != 15) { return false; } fromISODateTime(val); return true; } catch (Throwable t) { return false; } }
java
public static Date fromDate(final String dt) throws BadDateException { try { if (dt == null) { return null; } if (dt.indexOf("T") > 0) { return fromDateTime(dt); } if (!dt.contains("-")) { return fromISODate(dt); } return fromRfcDate(dt); } ca...
java
public static Date fromDateTime(final String dt) throws BadDateException { try { if (dt == null) { return null; } if (!dt.contains("-")) { return fromISODateTimeUTC(dt); } return fromRfcDateTimeUTC(dt); } catch (Throwable t) { throw new BadDateException(); ...
java
public AbstractModule createModule() { return new AbstractModule() { @Override protected void configure() { bind(IDataFactory.class).to(mDataFacClass); bind(IMetaEntryFactory.class).to(mMetaFacClass); bind(IRevisioning.class).to(mRevisionin...
java
public void setProperty(final String name, final String val) { if (props == null) { props = new Properties(); } props.setProperty(name, val); }
java
public void startEmit(final Writer wtr, final String dtd) throws IOException { this.wtr = wtr; this.dtd = dtd; }
java
public void openTag(final QName tag, final String attrName, final String attrVal) throws IOException { blanks(); openTagSameLine(tag, attrName, attrVal); newline(); indent += 2; }
java
public void openTagSameLine(final QName tag, final String attrName, final String attrVal) throws IOException { lb(); emitQName(tag); attribute(attrName, attrVal); endOpeningTag(); }
java
private void value(final String val, final String quoteChar) throws IOException { if (val == null) { return; } String q = quoteChar; if (q == null) { q = ""; } if ((val.indexOf('&') >= 0) || (val.indexOf('<') >= 0)) { out("<![CDATA["); out(q...
java
public OptionElement parseOptions(final InputStream is) throws OptionsException{ Reader rdr = null; try { rdr = new InputStreamReader(is); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(false); DocumentBuilder builder = factory.newDocu...
java
public void toXml(final OptionElement root, final OutputStream str) throws OptionsException { Writer wtr = null; try { XmlEmit xml = new XmlEmit(true); wtr = new OutputStreamWriter(str); xml.startEmit(wtr); xml.openTag(outerTag); for (OptionElement oe: root.getChildren()) { ...
java
@Override public Object getProperty(final String name) throws OptionsException { Object val = getOptProperty(name); if (val == null) { throw new OptionsException("Missing property " + name); } return val; }
java
@Override public String getStringProperty(final String name) throws OptionsException { Object val = getProperty(name); if (!(val instanceof String)) { throw new OptionsException("org.bedework.calenv.bad.option.value"); } return (String)val; }
java
public Collection match(final String name) throws OptionsException { if (useSystemwideValues) { return match(optionsRoot, makePathElements(name), -1); } return match(localOptionsRoot, makePathElements(name), -1); }
java
public static String getProperty(final MessageResources msg, final String pname, final String def) throws Throwable { String p = msg.getMessage(pname); if (p == null) { return def; } return p; }
java
public static String getReqProperty(final MessageResources msg, final String pname) throws Throwable { String p = getProperty(msg, pname, null); if (p == null) { logger.error("No definition for property " + pname); throw new Exception(": No definition for prope...
java
public static boolean getBoolProperty(final MessageResources msg, final String pname, final boolean def) throws Throwable { String p = msg.getMessage(pname); if (p == null) { return def; } return Boolean.valueOf(p); ...
java
public static int getIntProperty(final MessageResources msg, final String pname, final int def) throws Throwable { String p = msg.getMessage(pname); if (p == null) { return def; } return Integer.valueOf(p); }
java
public static MessageEmit getErrorObj(final HttpServletRequest request, final String errorObjAttrName) { if (errorObjAttrName == null) { // don't set return null; } HttpSession sess = request.getSession(false); if (sess == null) { logger.error(...
java
public static MessageEmit getMessageObj(final HttpServletRequest request, final String messageObjAttrName) { if (messageObjAttrName == null) { // don't set return null; } HttpSession sess = request.getSession(false); if (sess == null) { logge...
java
public static double quickRatio(final String paramFirst, final String paramSecond) { if (paramFirst == null || paramSecond == null) { return 1; } double matches = 0; // Use a sparse array to reduce the memory usage // for unicode characters. final int x[][] =...
java
public ObjectName createCustomComponentMBeanName(final String type, final String name) { ObjectName result = null; String tmp = jmxDomainName + ":" + "type=" + sanitizeString(type) + ",name=" + sanitizeString(name); try { result = new ObjectName(tmp); } catch (Mal...
java
public static ObjectName getSystemObjectName(final String domainName, final String containerName, final Class theClass) throws MalformedObjectNameException { String tmp = domainName + ":" + "type=" + theCl...
java
public void unregisterMBean(final ObjectName name) throws JMException { if ((beanServer != null) && beanServer.isRegistered(name) && registeredMBeanNames.remove(name)) { beanServer.unregisterMBean(name); } }
java
public void set(final T paramOrigin, final T paramDestination, final boolean paramBool) { assert paramOrigin != null; assert paramDestination != null; if (!mMap.containsKey(paramOrigin)) { mMap.put(paramOrigin, new IdentityHashMap<T, Boolean>()); } mMap.get(paramOrig...
java
public boolean get(final T paramOrigin, final T paramDestination) { assert paramOrigin != null; assert paramDestination != null; if (!mMap.containsKey(paramOrigin)) { return false; } final Boolean bool = mMap.get(paramOrigin).get(paramDestination); return boo...
java
public void toStringSegment(final ToString ts) { ts.append("sysCode", String.valueOf(getSysCode())); ts.append("dtstamp", getDtstamp()); ts.append("sequence", getSequence()); }
java
public synchronized byte[] toByteArray() { byte[] outBuff = new byte[count]; int pos = 0; for (BufferPool.Buffer b: buffers) { System.arraycopy(b.buf, 0, outBuff, pos, b.pos); pos += b.pos; } return outBuff; }
java
public void release() throws IOException { for (BufferPool.Buffer b: buffers) { PooledBuffers.release(b); } buffers.clear(); count = 0; }
java
public static boolean createFolderStructure(final File pFile, IConfigurationPath[] pPaths) throws TTIOException { boolean returnVal = true; pFile.mkdirs(); // creation of folder structure for (IConfigurationPath paths : pPaths) { final File toCreate = new File(pFile, ...
java
public static int compareStructure(final File pFile, IConfigurationPath[] pPaths) { int existing = 0; for (final IConfigurationPath path : pPaths) { final File currentFile = new File(pFile, path.getFile().getName()); if (currentFile.exists()) { existing++; ...
java
public static synchronized void invokeFullDiff(final Builder paramBuilder) throws TTException { checkParams(paramBuilder); DiffKind.FULL.invoke(paramBuilder); }
java
public static synchronized void invokeStructuralDiff(final Builder paramBuilder) throws TTException { checkParams(paramBuilder); DiffKind.STRUCTURAL.invoke(paramBuilder); }
java
private static void checkParams(final Builder paramBuilder) { checkState(paramBuilder.mSession != null && paramBuilder.mKey >= 0 && paramBuilder.mNewRev >= 0 && paramBuilder.mOldRev >= 0 && paramBuilder.mObservers != null && paramBuilder.mKind != null, "No valid arguments specified!"); ...
java
public boolean equalsAllBut(DirRecord that, String[] attrIDs) throws NamingException { if (attrIDs == null) throw new NamingException("DirectoryRecord: null attrID list"); if (!dnEquals(that)) { return false; } int n = attrIDs.length; if (n == 0) return true; Attributes thisAttrs...
java
public boolean dnEquals(DirRecord that) throws NamingException { if (that == null) { throw new NamingException("Null record for dnEquals"); } String thisDn = getDn(); if (thisDn == null) { throw new NamingException("No dn for this record"); } String thatDn = that.getDn(); if (t...
java
public void addAttr(String attr, Object val) throws NamingException { // System.out.println("addAttr " + attr); Attribute a = findAttr(attr); if (a == null) { setAttr(attr, val); } else { a.add(val); } }
java
public boolean contains(Attribute attr) throws NamingException { if (attr == null) { return false; // protect } Attribute recAttr = getAttributes().get(attr.getID()); if (recAttr == null) { return false; } NamingEnumeration ne = attr.getAll(); while (ne.hasMore()) { if ...
java
public NamingEnumeration attrElements(String attr) throws NamingException { Attribute a = findAttr(attr); if (a == null) { return null; } return a.getAll(); }
java
private void emitEndTag() throws TTIOException { final long nodeKey = mRtx.getNode().getDataKey(); mEvent = mFac.createEndElement(mRtx.getQNameOfCurrentNode(), new NamespaceIterator(mRtx)); mRtx.moveTo(nodeKey); }
java
private void emitNode() throws TTIOException { switch (mRtx.getNode().getKind()) { case ROOT: mEvent = mFac.createStartDocument(); break; case ELEMENT: final long key = mRtx.getNode().getDataKey(); final QName qName = mRtx.getQNameOfCurrentNode(); ...
java
private void emit() throws TTIOException { // Emit pending end elements. if (mCloseElements) { if (!mStack.empty() && mStack.peek() != ((ITreeStructData)mRtx.getNode()).getLeftSiblingKey()) { mRtx.moveTo(mStack.pop()); emitEndTag(); mRtx.moveTo...
java
private boolean isBooleanFalse() { if (getNode().getDataKey() >= 0) { return false; } else { // is AtomicValue if (getNode().getTypeKey() == NamePageHash.generateHashForString("xs:boolean")) { // atomic value of type boolean // return true, if ato...
java
private String expandString() { final FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.SMALL); try { final INodeReadTrx rtx = createRtxAndMove(); final FilterAxis axis = new FilterAxis(new DescendantAxis(rtx), rtx, new TextFilter(rtx)); while (axis.hasNex...
java
public int getTypeAnnotation() { int type = 0; if (nodeKind == ATTRIBUTE) { type = StandardNames.XS_UNTYPED_ATOMIC; } else { type = StandardNames.XS_UNTYPED; } return type; }
java
public boolean walk(OutputHandler outputHandler) throws IOException { try (ZipFile zipFile = new ZipFile(zip)) { // walk all entries and look for matches Enumeration<? extends ZipEntry> entries = zipFile.entries(); while(entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); // first c...
java
public void updateConfigInfo(final HttpServletRequest request, final XSLTConfig xcfg) throws ServletException { PresentationState ps = getPresentationState(request); if (ps == null) { // Still can't do a thing return; } if (xcfg.nextCfg == null) { ...
java
protected PresentationState getPresentationState(HttpServletRequest request) { String attrName = getPresentationAttrName(); if ((attrName == null) || (attrName.equals("NONE"))) { return null; } /* First try the request */ Object o = request.getAttribute(attrName); if (o == nul...
java