@NotNull public static String getVFileName(int nameId) { IntObjectLinkedMap.MapEntry<Object> entry = getEntry(nameId); Object name = entry.value; if (name instanceof String) { //noinspection StringEquality return (String)name; } byte[] bytes = (byte[])name; int length = bytes.length; char[] chars = new char[length]; for (int i = 0; i < length; i++) { chars[i] = (char)bytes[i]; } return StringFactory.createShared(chars); }
private void scanSourceFile(File file, final Set<String> usedPackages) { myProgress.setText2(file.getName()); try { final char[] chars = FileUtil.loadFileText(file); scanSourceFileForImportedPackages(StringFactory.createShared(chars), new Consumer<String>() { public void consume(final String s) { usedPackages.add(myInterner.intern(s)); } }); } catch (IOException e) { LOG.info(e); } }
private static void addChunk(@NotNull CharSequence chars, int start, int end, @NotNull TextAttributes originalAttrs, boolean bold, @Nullable UsageType usageType, @NotNull List<TextChunk> result) { if (start >= end) return; TextAttributes attrs = bold ? TextAttributes.merge(originalAttrs, new TextAttributes(null, null, null, null, Font.BOLD)) : originalAttrs; result.add(new TextChunk(attrs, StringFactory.createShared(CharArrayUtil.fromSequence(chars, start, end)), usageType)); }
/** * Gets the relative path of <code>file</code> to its <code>ancestor</code>. Uses <code>separator</code> for * separating files. * * @param file the file * @param ancestor parent file * @param separator character to use as files separator * @return the relative path or {@code null} if {@code ancestor} is not ancestor for {@code file} */ @Nullable public static String getRelativePath(@NotNull VirtualFile file, @NotNull VirtualFile ancestor, char separator) { if (!file.getFileSystem().equals(ancestor.getFileSystem())) { return null; } int length = 0; VirtualFile parent = file; while (true) { if (parent == null) return null; if (parent.equals(ancestor)) break; if (length > 0) { length++; } length += parent.getNameSequence().length(); parent = parent.getParent(); } char[] chars = new char[length]; int index = chars.length; parent = file; while (true) { if (parent.equals(ancestor)) break; if (index < length) { chars[--index] = separator; } CharSequence name = parent.getNameSequence(); for (int i = name.length() - 1; i >= 0; i--) { chars[--index] = name.charAt(i); } parent = parent.getParent(); } return StringFactory.createShared(chars); }
@NotNull public static String loadText(@NotNull VirtualFile file, int length) throws IOException { InputStreamReader reader = new InputStreamReader(file.getInputStream(), file.getCharset()); try { return StringFactory.createShared(FileUtil.loadText(reader, length)); } finally { reader.close(); } }
@Override @NotNull public String getUrl() { String protocol = getFileSystem().getProtocol(); int prefixLen = protocol.length() + "://".length(); char[] chars = appendPathOnFileSystem(prefixLen, new int[]{prefixLen}); copyString(chars, copyString(chars, 0, protocol), "://"); return StringFactory.createShared(chars); }
@NotNull public static byte[] printDocument(@NotNull Document document, String lineSeparator) throws IOException { CharArrayWriter writer = new CharArrayWriter(); writeDocument(document, writer, lineSeparator); return StringFactory.createShared(writer.toCharArray()).getBytes(CharsetToolkit.UTF8_CHARSET); }
@NotNull @Contract(pure = true) public static String repeatSymbol(final char aChar, final int count) { char[] buffer = new char[count]; Arrays.fill(buffer, aChar); return StringFactory.createShared(buffer); }
/** * @deprecated use #capitalize(String) */ @Contract(value = "null -> null; !null -> !null", pure = true) public static String firstLetterToUpperCase(@Nullable final String displayString) { if (displayString == null || displayString.isEmpty()) return displayString; char firstChar = displayString.charAt(0); char uppedFirstChar = toUpperCase(firstChar); if (uppedFirstChar == firstChar) return displayString; char[] buffer = displayString.toCharArray(); buffer[0] = uppedFirstChar; return StringFactory.createShared(buffer); }
@NotNull public static String loadTextAndClose(@NotNull Reader reader) throws IOException { try { return StringFactory.createShared(adaptiveLoadText(reader)); } finally { reader.close(); } }
@NotNull public static CharSequence uncompressStringRawBytes(@NotNull Object compressed) { if (compressed instanceof CharSequence) return (CharSequence)compressed; byte[] b = (byte[])compressed; try { int uncompressedLength = Snappy.getUncompressedLength(b, 0); byte[] bytes = spareBufferLocal.getBuffer(uncompressedLength); int bytesLength = Snappy.uncompress(b, 0, b.length, bytes, 0); ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes, 0, bytesLength); @NotNull DataInput in = new DataInputStream(byteStream); int len = DataInputOutputUtil.readINT(in); char[] chars = new char[len]; for (int i=0; i<len; i++) { int c = DataInputOutputUtil.readINT(in); chars[i] = (char)c; } return StringFactory.createShared(chars); } catch (CorruptionException ex) { throw new RuntimeException(ex); } catch (IOException e) { throw new RuntimeException(e); } }
@Nullable public static String getRelativePathFromAncestor(PsiFileSystemItem file, PsiFileSystemItem ancestor) { int length = 0; PsiFileSystemItem parent = file; while (true) { if (parent == null) return null; if (parent.equals(ancestor)) break; if (length > 0) { length++; } length += parent.getName().length(); parent = parent.getParent(); } char[] chars = new char[length]; int index = chars.length; parent = file; while (true) { if (parent.equals(ancestor)) break; if (index < length) { chars[--index] = '/'; } String name = parent.getName(); for (int i = name.length() - 1; i >= 0; i--) { chars[--index] = name.charAt(i); } parent = parent.getParent(); } return StringFactory.createShared(chars); }
@NotNull private static String createSequence(@NotNull CharSequence text, int startOffset, int endOffset) { if (text instanceof String) { return ((String)text).substring(startOffset, endOffset); } char[] buf = new char[endOffset - startOffset]; CharArrayUtil.getChars(text, buf, startOffset, 0, buf.length); return StringFactory.createShared(buf); // this way the .toString() doesn't create another instance (as opposed to new CharArrayCharSequence()) }
private static void addChunk(@NotNull CharSequence chars, int start, int end, @NotNull TextAttributes originalAttrs, boolean bold, @NotNull List<TextChunk> result) { if (start >= end) return; TextAttributes attrs = bold ? TextAttributes.merge(originalAttrs, new TextAttributes(null, null, null, null, Font.BOLD)) : originalAttrs; result.add(new TextChunk(attrs, StringFactory.createShared(CharArrayUtil.fromSequence(chars, start, end)))); }
public static String doGetRelative(VirtualFile file, VirtualFile ancestor, char separator) { int length = 0; VirtualFile parent = file; while (true) { if (parent == null) return null; if (parent.equals(ancestor)) break; if (length > 0) { length++; } length += parent.getName().length(); parent = parent.getParent(); } char[] chars = new char[length]; int index = chars.length; parent = file; while (true) { if (parent.equals(ancestor)) break; if (index < length) { chars[--index] = separator; } String name = parent.getName(); for (int i = name.length() - 1; i >= 0; i--) { chars[--index] = name.charAt(i); } parent = parent.getParent(); } return StringFactory.createShared(chars); }
@Override @NotNull public String getUrl() { String protocol = getFileSystem().getProtocol(); int prefixLen = protocol.length() + "://".length(); int[] pos = {prefixLen}; char[] chars = appendPathOnFileSystem(prefixLen, pos); copyString(chars, copyString(chars, 0, protocol), "://"); return chars.length == pos[0] ? StringFactory.createShared(chars) : new String(chars, 0, pos[0]); }
@Override @NotNull public String getPath() { int[] pos = {0}; char[] chars = appendPathOnFileSystem(0, pos); return chars.length == pos[0] ? StringFactory.createShared(chars) : new String(chars, 0, pos[0]); }
@NotNull public static byte[] printDocument(@NotNull Document document, String lineSeparator) throws IOException { CharArrayWriter writer = new CharArrayWriter(); writeDocument(document, writer, lineSeparator); return StringFactory.createShared(writer.toCharArray()).getBytes(ENCODING); }
/** * @deprecated use #capitalize(String) */ @Nullable public static String firstLetterToUpperCase(@Nullable final String displayString) { if (displayString == null || displayString.isEmpty()) return displayString; char firstChar = displayString.charAt(0); char uppedFirstChar = toUpperCase(firstChar); if (uppedFirstChar == firstChar) return displayString; char[] buffer = displayString.toCharArray(); buffer[0] = uppedFirstChar; return StringFactory.createShared(buffer); }
@NotNull private static String createSequence(@NotNull CharSequence text) { char[] buf = new char[text.length()]; CharArrayUtil.getChars(text, buf, 0); return StringFactory.createShared(buf); // this way the .toString() doesn't create another instance (as opposed to new CharArrayCharSequence()) }
/** * Gets the relative path of <code>file</code> to its <code>ancestor</code>. Uses <code>separator</code> for * separating files. * * @param file the file * @param ancestor parent file * @param separator character to use as files separator * @return the relative path or {@code null} if {@code ancestor} is not ancestor for {@code file} */ @Nullable public static String getRelativePath(@Nonnull VirtualFile file, @Nonnull VirtualFile ancestor, char separator) { if (!file.getFileSystem().equals(ancestor.getFileSystem())) { return null; } int length = 0; VirtualFile parent = file; while (true) { if (parent == null) return null; if (parent.equals(ancestor)) break; if (length > 0) { length++; } length += parent.getNameSequence().length(); parent = parent.getParent(); } char[] chars = new char[length]; int index = chars.length; parent = file; while (true) { if (parent.equals(ancestor)) break; if (index < length) { chars[--index] = separator; } CharSequence name = parent.getNameSequence(); for (int i = name.length() - 1; i >= 0; i--) { chars[--index] = name.charAt(i); } parent = parent.getParent(); } return StringFactory.createShared(chars); }
@Nonnull public static String loadText(@Nonnull VirtualFile file, int length) throws IOException { InputStreamReader reader = new InputStreamReader(file.getInputStream(), file.getCharset()); try { return StringFactory.createShared(FileUtil.loadText(reader, length)); } finally { reader.close(); } }
@Override @Nonnull public String getUrl() { String protocol = getFileSystem().getProtocol(); int prefixLen = protocol.length() + "://".length(); char[] chars = appendPathOnFileSystem(prefixLen, new int[]{prefixLen}); copyString(chars, copyString(chars, 0, protocol), "://"); return StringFactory.createShared(chars); }
@Nonnull public static byte[] printDocument(@Nonnull Document document, String lineSeparator) throws IOException { CharArrayWriter writer = new CharArrayWriter(); writeDocument(document, writer, lineSeparator); return StringFactory.createShared(writer.toCharArray()).getBytes(CharsetToolkit.UTF8_CHARSET); }
@Nonnull @Contract(pure = true) public static String repeatSymbol(final char aChar, final int count) { char[] buffer = new char[count]; Arrays.fill(buffer, aChar); return StringFactory.createShared(buffer); }
@Nonnull public static String loadTextAndClose(@Nonnull Reader reader) throws IOException { try { return StringFactory.createShared(adaptiveLoadText(reader)); } finally { reader.close(); } }
@Nonnull public static CharSequence uncompressStringRawBytes(@Nonnull Object compressed) { if (compressed instanceof CharSequence) return (CharSequence)compressed; byte[] b = (byte[])compressed; try { int uncompressedLength = Snappy.getUncompressedLength(b, 0); byte[] bytes = spareBufferLocal.getBuffer(uncompressedLength); int bytesLength = Snappy.uncompress(b, 0, b.length, bytes, 0); ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes, 0, bytesLength); @Nonnull DataInput in = new DataInputStream(byteStream); int len = DataInputOutputUtil.readINT(in); char[] chars = new char[len]; for (int i=0; i<len; i++) { int c = DataInputOutputUtil.readINT(in); chars[i] = (char)c; } return StringFactory.createShared(chars); } catch (CorruptionException ex) { throw new RuntimeException(ex); } catch (IOException e) { throw new RuntimeException(e); } }
@Nonnull private static String createSequence(@Nonnull CharSequence text, int startOffset, int endOffset) { if (text instanceof String) { return ((String)text).substring(startOffset, endOffset); } char[] buf = new char[endOffset - startOffset]; CharArrayUtil.getChars(text, buf, startOffset, 0, buf.length); return StringFactory.createShared(buf); // this way the .toString() doesn't create another instance (as opposed to new CharArrayCharSequence()) }
@Override protected CharSequence loadText(final File file) throws IOException { return StringFactory.createShared(loadFileTextSkippingBom(file)); }
@Override @NotNull public String getPath() { return StringFactory.createShared(appendPathOnFileSystem(0, new int[]{0})); }
public static String convertSeparators(String s) { return StringFactory.createShared(convertSeparators(s.toCharArray())); }
public static String readTextFrom(Reader reader) throws IOException { return StringFactory.createShared(readText(reader)); }
public static String encode(@NotNull byte[] octetString) { int bits24; int bits6; char[] out = new char[((octetString.length - 1) / 3 + 1) * 4]; int outIndex = 0; int i = 0; while ((i + 3) <= octetString.length) { // store the octets bits24 = (octetString[i++] & 0xFF) << 16; bits24 |= (octetString[i++] & 0xFF) << 8; bits24 |= (octetString[i++] & 0xFF); bits6 = (bits24 & 0x00FC0000) >> 18; out[outIndex++] = alphabet[bits6]; bits6 = (bits24 & 0x0003F000) >> 12; out[outIndex++] = alphabet[bits6]; bits6 = (bits24 & 0x00000FC0) >> 6; out[outIndex++] = alphabet[bits6]; bits6 = (bits24 & 0x0000003F); out[outIndex++] = alphabet[bits6]; } if (octetString.length - i == 2) { // store the octets bits24 = (octetString[i] & 0xFF) << 16; bits24 |= (octetString[i + 1] & 0xFF) << 8; bits6 = (bits24 & 0x00FC0000) >> 18; out[outIndex++] = alphabet[bits6]; bits6 = (bits24 & 0x0003F000) >> 12; out[outIndex++] = alphabet[bits6]; bits6 = (bits24 & 0x00000FC0) >> 6; out[outIndex++] = alphabet[bits6]; // padding out[outIndex] = '='; } else if (octetString.length - i == 1) { // store the octets bits24 = (octetString[i] & 0xFF) << 16; bits6 = (bits24 & 0x00FC0000) >> 18; out[outIndex++] = alphabet[bits6]; bits6 = (bits24 & 0x0003F000) >> 12; out[outIndex++] = alphabet[bits6]; // padding out[outIndex++] = '='; out[outIndex] = '='; } return StringFactory.createShared(out); }
/** * Returns reversed string by unique hash code. */ public String getReversedString(int hashCode) { return StringFactory.createShared(getReversedChars(hashCode)); }