本文整理汇总了Java中com.intellij.util.ArrayUtil.startsWith方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayUtil.startsWith方法的具体用法?Java ArrayUtil.startsWith怎么用?Java ArrayUtil.startsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.util.ArrayUtil
的用法示例。
在下文中一共展示了ArrayUtil.startsWith方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createModuleItems
import com.intellij.util.ArrayUtil; //导入方法依赖的package包/类
@NotNull
private static Collection<? extends PackagingSourceItem> createModuleItems(@NotNull ArtifactEditorContext editorContext, @NotNull String[] groupPath) {
final Module[] modules = editorContext.getModulesProvider().getModules();
final List<PackagingSourceItem> items = new ArrayList<PackagingSourceItem>();
Set<String> groups = new HashSet<String>();
for (Module module : modules) {
String[] path = ModuleManager.getInstance(editorContext.getProject()).getModuleGroupPath(module);
if (path == null) {
path = ArrayUtil.EMPTY_STRING_ARRAY;
}
if (Comparing.equal(path, groupPath)) {
items.add(new ModuleSourceItemGroup(module));
}
else if (ArrayUtil.startsWith(path, groupPath)) {
groups.add(path[groupPath.length]);
}
}
for (String group : groups) {
items.add(0, new ModuleGroupItem(ArrayUtil.append(groupPath, group)));
}
return items;
}
示例2: isSafeToReloadIn
import com.intellij.util.ArrayUtil; //导入方法依赖的package包/类
static Magic8 isSafeToReloadIn(@NotNull VirtualFile virtualFile, @NotNull String text, @NotNull byte[] bytes, @NotNull Charset charset) {
// file has BOM but the charset hasn't
byte[] bom = virtualFile.getBOM();
if (bom != null && !CharsetToolkit.canHaveBom(charset, bom)) return Magic8.NO_WAY;
// the charset has mandatory BOM (e.g. UTF-xx) but the file hasn't or has wrong
byte[] mandatoryBom = CharsetToolkit.getMandatoryBom(charset);
if (mandatoryBom != null && !ArrayUtil.startsWith(bytes, mandatoryBom)) return Magic8.NO_WAY;
String loaded = LoadTextUtil.getTextByBinaryPresentation(bytes, charset).toString();
String separator = FileDocumentManager.getInstance().getLineSeparator(virtualFile, null);
String toSave = StringUtil.convertLineSeparators(loaded, separator);
String failReason = LoadTextUtil.wasCharsetDetectedFromBytes(virtualFile);
if (failReason != null && CharsetToolkit.UTF8_CHARSET.equals(virtualFile.getCharset()) && !CharsetToolkit.UTF8_CHARSET.equals(charset)) {
return Magic8.NO_WAY; // can't reload utf8-autodetected file in another charset
}
byte[] bytesToSave;
try {
bytesToSave = toSave.getBytes(charset);
}
catch (UnsupportedOperationException e) {
return Magic8.NO_WAY;
}
if (bom != null && !ArrayUtil.startsWith(bytesToSave, bom)) {
bytesToSave = ArrayUtil.mergeArrays(bom, bytesToSave); // for 2-byte encodings String.getBytes(Charset) adds BOM automatically
}
return !Arrays.equals(bytesToSave, bytes) ? Magic8.NO_WAY : loaded.equals(text) ? Magic8.ABSOLUTELY : Magic8.WELL_IF_YOU_INSIST;
}
示例3: extractXmlEncodingFromProlog
import com.intellij.util.ArrayUtil; //导入方法依赖的package包/类
@Nullable
public static String extractXmlEncodingFromProlog(@NotNull byte[] bytes) {
int index = 0;
if (CharsetToolkit.hasUTF8Bom(bytes)) {
index = CharsetToolkit.UTF8_BOM.length;
}
index = skipWhiteSpace(index, bytes);
if (!ArrayUtil.startsWith(bytes, index, XML_PROLOG_START_BYTES)) return null;
index += XML_PROLOG_START_BYTES.length;
while (index < bytes.length) {
index = skipWhiteSpace(index, bytes);
if (ArrayUtil.startsWith(bytes, index, XML_PROLOG_END_BYTES)) return null;
if (ArrayUtil.startsWith(bytes, index, ENCODING_BYTES)) {
index += ENCODING_BYTES.length;
index = skipWhiteSpace(index, bytes);
if (index >= bytes.length || bytes[index] != '=') continue;
index++;
index = skipWhiteSpace(index, bytes);
if (index >= bytes.length || bytes[index] != '\'' && bytes[index] != '\"') continue;
byte quote = bytes[index];
index++;
StringBuilder encoding = new StringBuilder();
while (index < bytes.length) {
if (bytes[index] == quote) return encoding.toString();
encoding.append((char)bytes[index++]);
}
}
index++;
}
return null;
}
示例4: hasUTF32BEBom
import com.intellij.util.ArrayUtil; //导入方法依赖的package包/类
public static boolean hasUTF32BEBom(@NotNull byte[] bom) {
return ArrayUtil.startsWith(bom, UTF32BE_BOM);
}
示例5: hasUTF32LEBom
import com.intellij.util.ArrayUtil; //导入方法依赖的package包/类
public static boolean hasUTF32LEBom(@NotNull byte[] bom) {
return ArrayUtil.startsWith(bom, UTF32LE_BOM);
}
示例6: hasUTF8Bom
import com.intellij.util.ArrayUtil; //导入方法依赖的package包/类
/**
* Has a Byte Order Marker for UTF-8 (Used by Microsoft's Notepad and other editors).
*
* @param bom a buffer.
* @return true if the buffer has a BOM for UTF8.
*/
public static boolean hasUTF8Bom(@NotNull byte[] bom) {
return ArrayUtil.startsWith(bom, UTF8_BOM);
}
示例7: hasUTF16LEBom
import com.intellij.util.ArrayUtil; //导入方法依赖的package包/类
/**
* Has a Byte Order Marker for UTF-16 Low Endian
* (ucs-2le, ucs-4le, and ucs-16le).
*
* @param bom a buffer.
* @return true if the buffer has a BOM for UTF-16 Low Endian.
*/
public static boolean hasUTF16LEBom(@NotNull byte[] bom) {
return ArrayUtil.startsWith(bom, UTF16LE_BOM);
}
示例8: hasUTF16BEBom
import com.intellij.util.ArrayUtil; //导入方法依赖的package包/类
/**
* Has a Byte Order Marker for UTF-16 Big Endian
* (utf-16 and ucs-2).
*
* @param bom a buffer.
* @return true if the buffer has a BOM for UTF-16 Big Endian.
*/
public static boolean hasUTF16BEBom(@NotNull byte[] bom) {
return ArrayUtil.startsWith(bom, UTF16BE_BOM);
}