@NotNull public static String getLibraryName(@NotNull Library library) { final String result = library.getName(); if (result != null) { return result; } String[] endingsToStrip = {"/", "!", ".jar"}; StringBuilder buffer = new StringBuilder(); for (OrderRootType type : OrderRootType.getAllTypes()) { for (String url : library.getUrls(type)) { buffer.setLength(0); buffer.append(url); for (String ending : endingsToStrip) { if (buffer.lastIndexOf(ending) == buffer.length() - ending.length()) { buffer.setLength(buffer.length() - ending.length()); } } final int i = buffer.lastIndexOf(PATH_SEPARATOR); if (i < 0 || i >= buffer.length() - 1) { continue; } String candidate = buffer.substring(i + 1); if (!StringUtil.isEmpty(candidate)) { return candidate; } } } assert false; return "unknown-lib"; }
@Override protected void processFile(BufferedReader inFile, BufferedWriter outFile, FilterContext fc) throws IOException, TranslationException { out = outFile; READ_STATE state = READ_STATE.WAIT_TIME; key = null; text.setLength(0); String s; while ((s = inFile.readLine()) != null) { switch (state) { case WAIT_TIME: if (PATTERN_TIME_INTERVAL.matcher(s).matches()) { state = READ_STATE.WAIT_TEXT; } key = s; text.setLength(0); outFile.write(s); outFile.write(EOL); break; case WAIT_TEXT: if (s.trim().isEmpty()) { flush(); outFile.write(EOL); state = READ_STATE.WAIT_TIME; } if (text.length() > 0) { text.append('\n'); } text.append(s); break; } } flush(); }
public String siguienteInstruccion() throws IOException { String instruccion = null; if (buffer.length() > 0) { int pos = buscaChar(buffer, 0, buffer.length(), ';'); if (pos > 0) { instruccion = buffer.substring(0, pos); buffer = new StringBuilder(buffer.substring(pos + 1, buffer.length())); } } else { char[] cbuf = new char[4 * 1024]; int leidos = 0; while ((instruccion == null) && ((leidos = reader.read(cbuf)) != -1)) { leidos = reemplazaSeparadorDeLinea(' ', cbuf, 0, leidos); int pos = buscaChar(cbuf, 0, leidos, ';'); if (pos > 0) { buffer.append(cbuf, 0, pos); instruccion = buffer.toString(); buffer.setLength(0); buffer.append(cbuf, pos + 1, leidos); } else { buffer.append(cbuf, 0, leidos); } } if (leidos == -1 && buffer.length() > 0) { instruccion = buffer.toString(); buffer.setLength(0); } } return instruccion; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(arg1); sb.append("\t"); sb.append(arg2); sb.append("\t"); for (Integer rel : Y) { sb.append(rel); sb.append("|"); } sb.setLength(sb.length() - 1); sb.append("\n"); for (int i = 0; i < numMentions; i++) { sb.append("Mention " + i + " "); for (int feat : features[i].ids) { sb.append(feat); sb.append(" "); } sb.append("\n"); } sb.setLength(sb.length() - 1); return sb.toString().trim(); }
public static String prepareFilters(final SearchRequest req) { final StringBuilder builder = new StringBuilder(Query.FETCH_IMAGES.toString()); // Add date filters builder.append(" where startedAt >= ? and endedAt <= ? "); if (req.getUserList() != null && req.getUserList().size() > 0) { // Add user name filters builder.append(" and userid in ("); int count = req.getUserList().size(); while (count-- > 0) builder.append("?,"); builder.setLength(builder.length() - 1); builder.append(") "); } // Add location filters if (req.getLocationList() != null && req.getLocationList().size() > 0) { builder.append(" and location in ("); int count = req.getLocationList().size(); while (count-- > 0) builder.append("?,"); builder.setLength(builder.length() - 1); builder.append(") "); } builder.append(" order by userid,startedAt;"); return builder.toString(); }
/** * Returns a map with variable bindings. * * @param opts main options * @return bindings */ public static HashMap<String, String> bindings(final MainOptions opts) { final HashMap<String, String> bindings = new HashMap<>(); final String bind = opts.get(MainOptions.BINDINGS).trim(); final StringBuilder key = new StringBuilder(); final StringBuilder val = new StringBuilder(); boolean first = true; final int sl = bind.length(); for (int s = 0; s < sl; s++) { final char ch = bind.charAt(s); if (first) { if (ch == '=') { first = false; } else { key.append(ch); } } else { if (ch == ',') { if (s + 1 == sl || bind.charAt(s + 1) != ',') { bindings.put(key.toString().trim(), val.toString()); key.setLength(0); val.setLength(0); first = true; continue; } // literal commas are escaped by a second comma s++; } val.append(ch); } } if (key.length() != 0) bindings.put(key.toString().trim(), val.toString()); return bindings; }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(name); if (getNameQualifiers() != null && getNameQualifiers().size() > 0) { sb.append('<'); for (Qualifier q : getNameQualifiers()) sb.append(q.getName()).append('=').append(q.getValue()).append(';'); sb.setLength(sb.length() - 1); sb.append('>'); } sb.append('=').append(value); if (getValueQualifiers() != null && getValueQualifiers().size() > 0) { sb.append('['); for (Qualifier q : getValueQualifiers()) sb.append(q.getName()).append('=').append(q.getValue()).append(';'); sb.setLength(sb.length() - 1); sb.append(']'); } return sb.toString(); }
private String readLine(int ci) { int last_ch = -1; fTmpBuffer.setLength(0); while (ci != -1 && ci != '\n' || last_ch == '\\') { if (last_ch == '\\' && ci == '\n') { if (fTmpBuffer.charAt(fTmpBuffer.length() - 1) == '\r') { fTmpBuffer.setLength(fTmpBuffer.length() - 1); } if (fTmpBuffer.charAt(fTmpBuffer.length() - 1) == '\\') { fTmpBuffer.setCharAt(fTmpBuffer.length() - 1, '\n'); } } else { fTmpBuffer.append((char) ci); } if (ci != '\r') { last_ch = ci; } ci = get_ch(); } unget_ch(ci); if (fTmpBuffer.length() == 0) { return null; } else { return fTmpBuffer.toString(); } }
private String readLine(ServletInputStream in) throws IOException { StringBuilder sbuf = new StringBuilder(); int result; do { result = in.readLine(buf, 0, buf.length); // does += if (result != -1) { sbuf.append(new String(buf, 0, result, encoding)); } } while (result == buf.length); // loop only if the buffer was filled if (sbuf.length() == 0) { return null; // nothing read, must be at the end of stream } // Cut off the trailing \n or \r\n // It should always be \r\n but IE5 sometimes does just \n // Thanks to Luke Blaikie for helping make this work with \n int len = sbuf.length(); if (len >= 2 && sbuf.charAt(len - 2) == '\r') { sbuf.setLength(len - 2); // cut \r\n } else if (len >= 1 && sbuf.charAt(len - 1) == '\n') { sbuf.setLength(len - 1); // cut \n } return sbuf.toString(); }
protected void calculateModelAttributes() { String pakkage = calculateJavaModelPackage(); StringBuilder sb = new StringBuilder(); sb.append(pakkage); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("Key"); // $NON-NLS-1$ setPrimaryKeyType(sb.toString()); sb.setLength(0); sb.append(pakkage); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); setBaseRecordType(sb.toString()); sb.setLength(0); sb.append(pakkage); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("WithBLOBs"); // $NON-NLS-1$ setRecordWithBLOBsType(sb.toString()); sb.setLength(0); sb.append(pakkage); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("Example"); // $NON-NLS-1$ setExampleType(sb.toString()); }
protected void calculateJavaClientAttributes() { if (context.getJavaClientGeneratorConfiguration() == null) { return; } StringBuilder sb = new StringBuilder(); sb.append(calculateJavaClientImplementationPackage()); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("DAOImpl"); // $NON-NLS-1$ setDAOImplementationType(sb.toString()); sb.setLength(0); sb.append(calculateJavaClientInterfacePackage()); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("DAO"); // $NON-NLS-1$ setDAOInterfaceType(sb.toString()); sb.setLength(0); sb.append(calculateJavaClientInterfacePackage()); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("Mapper"); // $NON-NLS-1$ setMyBatis3JavaMapperType(sb.toString()); sb.setLength(0); sb.append(calculateJavaClientInterfacePackage()); sb.append('.'); sb.append(fullyQualifiedTable.getDomainObjectName()); sb.append("SqlProvider"); // $NON-NLS-1$ setMyBatis3SqlProviderType(sb.toString()); }
/** Split command line into arguments. Allows " for words containing whitespaces. */ public static String[] splitArguments(String string) { assert string != null; ArrayList<String> result = new ArrayList<String>(); boolean escape = false; boolean inString = false; StringBuilder token = new StringBuilder(); for (int i = 0; i < string.length(); ++i) { char c = string.charAt(i); if (c == '"' && !escape) { if (inString) { result.add(token.toString()); token.setLength(0); } inString = !inString; } else if (Character.isWhitespace(c) && !inString) { if (token.length() > 0) { result.add(token.toString()); token.setLength(0); } } else token.append(c); escape = (c == '\\' && !escape); } if (token.length() > 0) result.add(token.toString()); return result.toArray(new String[result.size()]); }
/** * Creates the variables:<br> * basename_gn, where n=0...# of groups<br> * basename_g = number of groups (apart from g0) */ private void saveGroups(JMeterVariables vars, String basename, MatchResult match) { StringBuilder buf = new StringBuilder(); buf.append(basename); buf.append("_g"); // $NON-NLS-1$ int pfxlen = buf.length(); String prevString = vars.get(buf.toString()); int previous = 0; if (prevString != null) { try { previous = Integer.parseInt(prevString); } catch (NumberFormatException e) { log.warn("Could not parse " + prevString + " " + e); } } // Note: match.groups() includes group 0 final int groups = match.groups(); for (int x = 0; x < groups; x++) { buf.append(x); vars.put(buf.toString(), match.group(x)); buf.setLength(pfxlen); } vars.put(buf.toString(), Integer.toString(groups - 1)); for (int i = groups; i <= previous; i++) { buf.append(i); vars.remove(buf.toString()); // remove the remaining _gn vars buf.setLength(pfxlen); } }
private void generateParenthesis(StringBuilder parenthesis, int count, int n, List<String> list) { if (count == 0 && n == 0) { list.add(parenthesis.toString()); return; } if (count == 0) { parenthesis.append('('); generateParenthesis(parenthesis, count + 1, n - 1, list); parenthesis.setLength(parenthesis.length() - 1); } else { if (n != 0) { parenthesis.append('('); generateParenthesis(parenthesis, count + 1, n - 1, list); parenthesis.setLength(parenthesis.length() - 1); parenthesis.append(')'); generateParenthesis(parenthesis, count - 1, n, list); parenthesis.setLength(parenthesis.length() - 1); } else { parenthesis.append(')'); generateParenthesis(parenthesis, count - 1, n, list); parenthesis.setLength(parenthesis.length() - 1); } } }
private void helper(List<String> res, String s, StringBuilder path, int index) { if (s.length() == index) { // if the whole string has been decoded, return 1 res.add(path.toString()); return; } if (s.charAt(index) == '0') { return; } int length = path.length(); // first way of decoding by 1-digit num int num1 = Integer.valueOf(s.substring(index, index + 1)); path.append((char) ('A' + num1 - 1)); helper(res, s, path, index + 1); path.setLength(length); if (s.length() - 1 > index && isValidDouble( s.substring( index, index + 2))) { // if it can, there will be another way of decoding curr substring by // 2-digit num int num2 = Integer.valueOf(s.substring(index, index + 2)); path.append((char) ('A' + num2 - 1)); helper(res, s, path, index + 2); path.setLength(length); } }
public void loadSettings() { // if does not exist load default SharedPreferences settings = getActivity().getSharedPreferences(PREF_TITLE, 0); StringBuilder sb = new StringBuilder(); et_serv.setText(settings.getString(PREF_URL, DEFAULT_URL)); et_user.setText(settings.getString(PREF_USER, DEFAULT_USER)); et_pass.setText(settings.getString(PREF_PASS, DEFAULT_PASS)); et_thread.setText(sb.append(settings.getInt(PREF_THREAD, DEFAULT_THREAD)).toString()); sb.setLength(0); sb_throttle.setProgress((int) (settings.getFloat(PREF_THROTTLE, DEFAULT_THROTTLE) * 100)); et_scanTime.setText(sb.append(settings.getLong(PREF_SCANTIME, DEFAULT_SCANTIME)).toString()); sb.setLength(0); et_retryPause.setText( sb.append(settings.getLong(PREF_RETRYPAUSE, DEFAULT_RETRYPAUSE)).toString()); cb_service.setChecked(settings.getBoolean(PREF_BACKGROUND, DEFAULT_BACKGROUND)); cb_donate.setChecked(settings.getBoolean(PREF_DONATE, DEFAULT_DONATE)); if (settings.getInt(PREF_PRIORITY, DEFAULT_PRIORITY) == Thread.MIN_PRIORITY) { spn_priority.setSelection(0); } if (settings.getInt(PREF_PRIORITY, DEFAULT_PRIORITY) == Thread.NORM_PRIORITY) { spn_priority.setSelection(1); } if (settings.getInt(PREF_PRIORITY, DEFAULT_PRIORITY) == Thread.MAX_PRIORITY) { spn_priority.setSelection(2); } Toast.makeText(getActivity(), "Settings Loaded", Toast.LENGTH_SHORT).show(); }
public String memoryToString() { StringBuilder memoryData = new StringBuilder(); StringBuilder firstLine = new StringBuilder(); StringBuilder secondLine = new StringBuilder(); for (int i = 0; memory != null && i < memory.limit(); ++i) { byte value = memory.get(i); // Check if value is ASCII // (should be until 0x7e - but using 0x7f // to be compatible with cpp-ethereum) // See: https://github.com/ethereum/cpp-ethereum/issues/299 String character = ((byte) 0x20 <= value && value <= (byte) 0x7f) ? new String(new byte[] {value}) : "?"; firstLine.append(character).append(""); secondLine.append(Utils.oneByteToHexString(value)).append(" "); if ((i + 1) % 8 == 0) { String tmp = String.format("%4s", Integer.toString(i - 7, 16)).replace(" ", "0"); memoryData.append("").append(tmp).append(" "); memoryData.append(firstLine).append(" "); memoryData.append(secondLine); if (i + 1 < memory.limit()) memoryData.append("\n"); firstLine.setLength(0); secondLine.setLength(0); } } return memoryData.toString(); }
public List<String> write() { List<String> lines = new ArrayList<String>(); StringBuilder out = new StringBuilder(); for (Entry<String, Attribute> attribute : attributes.entrySet()) { out.append(attribute.getKey()).append(": "); Attribute attributeValue = attribute.getValue(); if (attributeValue.size() > 1) { lines.add(out.toString()); out.setLength(0); for (int i = 0; i < attributeValue.size(); i++) { Value value = attributeValue.get(i); out.append(" "); value.toString(out); if (i + 1 < attributeValue.size()) { out.append(","); } lines.add(out.toString()); out.setLength(0); } } else { attributeValue.toString("", out); lines.add(out.toString()); out.setLength(0); } } return lines; }
/* ------------------------------------------------------------------------------- */ private String takeString() { _string.setLength(_length); String s = _string.toString(); _string.setLength(0); _length = -1; return s; }
/** * Splits the given string in a list where each element is a line. * * @param string string to be splitted. * @return list of strings where each string is a line. * @note the new line characters are also added to the returned string. */ public static List<String> splitLines(final String string) { final ArrayList<String> ret = new ArrayList<>(); final int len = string.length(); char c; final StringBuilder buf = new StringBuilder(); for (int i = 0; i < len; i++) { c = string.charAt(i); buf.append(c); if (c == '\r') { if (i < len - 1 && string.charAt(i + 1) == '\n') { i++; buf.append('\n'); } ret.add(buf.toString()); buf.setLength(0); } if (c == '\n') { ret.add(buf.toString()); buf.setLength(0); } } if (buf.length() != 0) { ret.add(buf.toString()); } return ret; }
@Test public void testRead2() { Wire wire = createWire(); wire.write(); wire.write(BWKey.field1); String name1 = "Long field name which is more than 32 characters, Bye"; wire.write(() -> name1); // ok as blank matches anything StringBuilder name = new StringBuilder(); wire.read(name); assertEquals(0, name.length()); name.setLength(0); wire.read(name); assertEquals(numericField ? "1" : fieldLess ? "" : BWKey.field1.name(), name.toString()); name.setLength(0); wire.read(name); assertEquals(numericField ? "-1019176629" : fieldLess ? "" : name1, name.toString()); assertEquals(0, bytes.readRemaining()); // check it's safe to read too much. wire.read(); }
@Override public void execute(MapleClient c, MessageCallback mc, String[] splitted) throws Exception, IllegalCommandSyntaxException { if (splitted[0].equals("!whosthere")) { MessageCallback callback = new ServernoticeMapleClientMessageCallback(c); StringBuilder builder = new StringBuilder("Players on Map: "); for (MapleCharacter chr : c.getPlayer().getMap().getCharacters()) { if (builder.length() > 150) { // wild guess :o builder.setLength(builder.length() - 2); callback.dropMessage(builder.toString()); builder = new StringBuilder(); } builder.append(MapleCharacter.makeMapleReadable(chr.getName())); builder.append(", "); } builder.setLength(builder.length() - 2); c.getSession().write(MaplePacketCreator.serverNotice(6, builder.toString())); } else if (splitted[0].equals("!cheaters")) { try { List<CheaterData> cheaters = c.getChannelServer().getWorldInterface().getCheaters(c.getWorld()); for (int x = cheaters.size() - 1; x >= 0; x--) { CheaterData cheater = cheaters.get(x); mc.dropMessage(cheater.getInfo()); } } catch (RemoteException e) { c.getChannelServer().reconnectWorld(); } } }
private List<String> getAllSubwords(String line) { final ArrayList<String> subwords = new ArrayList<>(); for (int i = 0; i < line.length(); i++) { final char character = line.charAt(i); if (Character.isUpperCase(character) || Character.isDigit(character)) { if (mWordSinceLastCapitalBuilder.length() > 1) { subwords.add(mWordSinceLastCapitalBuilder.toString().toLowerCase()); } mWordSinceLastCapitalBuilder.setLength(0); } if (Character.isSpaceChar(character)) { subwords.add(mWordSinceLastSpaceBuilder.toString().toLowerCase()); if (mWordSinceLastCapitalBuilder.length() > 1 && mWordSinceLastCapitalBuilder.length() != mWordSinceLastSpaceBuilder.length()) { subwords.add(mWordSinceLastCapitalBuilder.toString().toLowerCase()); } mWordSinceLastCapitalBuilder.setLength(0); mWordSinceLastSpaceBuilder.setLength(0); } else { mWordSinceLastCapitalBuilder.append(character); mWordSinceLastSpaceBuilder.append(character); } } if (mWordSinceLastSpaceBuilder.length() > 0) { subwords.add(mWordSinceLastSpaceBuilder.toString().toLowerCase()); } if (mWordSinceLastCapitalBuilder.length() > 1 && mWordSinceLastCapitalBuilder.length() != mWordSinceLastSpaceBuilder.length()) { subwords.add(mWordSinceLastCapitalBuilder.toString().toLowerCase()); } mWordSinceLastSpaceBuilder.setLength(0); mWordSinceLastCapitalBuilder.setLength(0); return subwords; }
/** * 读取SQL语句。“/*”“-”“#”“REM”开头为注释,“;”为SQL结束。 * * @param fileName SQL文件地址 * @return List of SQL statements * @throws Exception */ public static List<String> readSql(String fileName) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), "UTF-8")); List<String> sqlList = new ArrayList<String>(); StringBuilder sqlSb = new StringBuilder(); String s = null; while ((s = br.readLine()) != null) { if (s.startsWith("/*") || s.startsWith("#") || s.startsWith("REM") || s.startsWith("-") || StringUtils.isBlank(s)) { continue; } if (s.endsWith(";")) { sqlSb.append(s); sqlSb.setLength(sqlSb.length() - 1); sqlList.add(sqlSb.toString()); sqlSb.setLength(0); } else { sqlSb.append(s); } } br.close(); return sqlList; }
private static String[] parse(String path, char escape, char filesep) { ArrayList<String> list = new ArrayList<String>(); StringBuilder buff = new StringBuilder(); for (int i = 0; i < path.length(); i++) { String lt = Text.lookupText(path, i, 2); if (lt.length() == 2) { char c0 = lt.charAt(0); char c1 = lt.charAt(1); if (c0 == escape) { buff.append(c1); i += 1; } else if (c0 == filesep) { list.add(buff.toString()); buff.setLength(0); } else { buff.append(c0); } } else if (lt.length() == 1) { char c0 = lt.charAt(0); if (c0 == escape) { } else if (c0 == filesep) { list.add(buff.toString()); buff.setLength(0); } else { buff.append(c0); } } } if (buff.length() > 0) list.add(buff.toString()); return list.toArray(new String[] {}); }
protected String buildSQL() { if (columnsMap.isEmpty() || table == null || "".equals(table)) { return null; } StringBuilder valBuf = new StringBuilder(); StringBuilder buf = new StringBuilder(64); buf.append("insert into "); buf.append(table); buf.append(" ("); valBuf.append(" values("); for (Entry<String, String> entry : columnsMap.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key == null || "".equals(key)) { return null; } buf.append(key); buf.append(','); valBuf.append("?,"); ConvertPattern cp = new DefaultPattern(); if (!cp.setPattern(value)) { return null; } convertors.add(cp); } buf.setLength(buf.length() - 1); valBuf.setLength(valBuf.length() - 1); buf.append(')'); valBuf.append(')'); buf.append(valBuf); return buf.toString(); }
@Test public void testFormatAddressJumpLocal2() { labels.newInstruction( new AssemblyInstruction("", 99, "", "blah", Collections.<String>emptyList(), "", labels)); labels.newInstruction( new AssemblyInstruction( "anno", 65534, "mod", "jne", asList("0x0000000000000100"), "", labels)); labels.newInstruction( new AssemblyInstruction( "anno", 65535, "mod", "jne", asList("0x0000000000001000"), "", labels)); sb.setLength(0); labels.formatAddress(256, sb); assertEquals("0x0000000000000100", sb.toString()); sb.setLength(0); labels.formatAddress(4096, sb); assertEquals("0x0000000000001000", sb.toString()); labels.buildLabels(); sb.setLength(0); labels.formatAddress(256, sb); assertEquals(" L0000", sb.toString()); sb.setLength(0); labels.formatAddress(4096, sb); assertEquals(" L0001", sb.toString()); sb.setLength(0); labels.formatAddress(65535, sb); assertEquals("0x000000000000ffff", sb.toString()); }
public static List<String> extractSources(final InputStream source) { final List<String> sources = new LinkedList<>(); final StringBuilder buf = new StringBuilder(); try (final BufferedReader reader = new BufferedReader(new InputStreamReader(source))) { String line = reader.readLine(); boolean beforeCypher = false; boolean inCypher = false; while (line != null) { final String trimmedLine = line.trim().replaceAll("[\\s]+", ""); // make sure only "graph" blocks are parsed if (inCypher && "----".equals(trimmedLine)) { inCypher = false; beforeCypher = false; final String result = buf.toString().toUpperCase(); if (result.contains("CREATE") || result.contains("LOAD CSV")) { sources.add(buf.toString()); buf.setLength(0); } } if (inCypher) { buf.append(line); buf.append("\n"); if (line.endsWith(";")) { sources.add(buf.toString()); buf.setLength(0); } } if ("[source,cypher]".equals(trimmedLine)) { beforeCypher = true; } if (beforeCypher && "----".equals(trimmedLine)) { inCypher = true; beforeCypher = false; } line = reader.readLine(); } } catch (IOException ioex) { ioex.printStackTrace(); } return sources; }
@Override public UriBuilder uri(URI uri) { if (uri == null) { throw new IllegalArgumentException("URI parameter is null"); } if (uri.getRawFragment() != null) { fragment = uri.getRawFragment(); } if (uri.isOpaque()) { scheme = uri.getScheme(); ssp = uri.getRawSchemeSpecificPart(); return this; } if (uri.getScheme() == null) { if (ssp != null) { if (uri.getRawSchemeSpecificPart() != null) { ssp = uri.getRawSchemeSpecificPart(); return this; } } } else { scheme = uri.getScheme(); } ssp = null; if (uri.getRawAuthority() != null) { if (uri.getRawUserInfo() == null && uri.getHost() == null && uri.getPort() == -1) { authority = uri.getRawAuthority(); userInfo = null; host = null; port = -1; } else { authority = null; if (uri.getRawUserInfo() != null) { userInfo = uri.getRawUserInfo(); } if (uri.getHost() != null) { host = uri.getHost(); } if (uri.getPort() != -1) { port = uri.getPort(); } } } if (uri.getRawPath() != null && uri.getRawPath().length() > 0) { path.setLength(0); path.append(uri.getRawPath()); } if (uri.getRawQuery() != null && uri.getRawQuery().length() > 0) { query.setLength(0); query.append(uri.getRawQuery()); } return this; }
/** can return null if there is a linked object instead of an embedded file */ private byte[] handlePackage(byte[] pkgBytes, Metadata metadata) throws IOException { // now parse the package header ByteArrayInputStream is = new ByteArrayInputStream(pkgBytes); readUShort(is); String displayName = readAnsiString(is); // should we add this to the metadata? readAnsiString(is); // iconFilePath readUShort(is); // iconIndex int type = readUShort(is); // type // 1 is link, 3 is embedded object // this only handles embedded objects if (type != 3) { return null; } // should we really be ignoring this filePathLen? readUInt(is); // filePathLen String ansiFilePath = readAnsiString(is); // filePath long bytesLen = readUInt(is); byte[] objBytes = initByteArray(bytesLen); is.read(objBytes); StringBuilder unicodeFilePath = new StringBuilder(); try { long unicodeLen = readUInt(is); for (int i = 0; i < unicodeLen; i++) { int lo = is.read(); int hi = is.read(); int sum = lo + 256 * hi; if (hi == -1 || lo == -1) { // stream ran out; empty SB and stop unicodeFilePath.setLength(0); break; } unicodeFilePath.append((char) sum); } } catch (IOException e) { // swallow; the unicode file path is optional and might not happen unicodeFilePath.setLength(0); } String fileNameToUse = ""; String pathToUse = ""; if (unicodeFilePath.length() > 0) { String p = unicodeFilePath.toString(); fileNameToUse = p; pathToUse = p; } else { fileNameToUse = displayName == null ? "" : displayName; pathToUse = ansiFilePath == null ? "" : ansiFilePath; } metadata.set(Metadata.RESOURCE_NAME_KEY, FilenameUtils.getName(fileNameToUse)); metadata.set(Metadata.EMBEDDED_RELATIONSHIP_ID, pathToUse); return objBytes; }