public void save(DataOutput out) throws IOException { lockData(); try { out.writeInt(myDeletedPaths.size()); for (String path : myDeletedPaths) { IOUtil.writeString(path, out); } out.writeInt(myFilesToRecompile.size()); for (Map.Entry<BuildRootDescriptor, Set<File>> entry : myFilesToRecompile.entrySet()) { IOUtil.writeString(entry.getKey().getRootId(), out); final Set<File> files = entry.getValue(); out.writeInt(files.size()); for (File file : files) { IOUtil.writeString(FileUtil.toSystemIndependentName(file.getPath()), out); } } } finally { unlockData(); } }
public void load(DataInputStream in, JpsModel model, final BuildRootIndex buildRootIndex) throws IOException { final TargetTypeRegistry registry = TargetTypeRegistry.getInstance(); int typeCount = in.readInt(); while (typeCount-- > 0) { final String typeId = IOUtil.readString(in); int targetCount = in.readInt(); BuildTargetType<?> type = registry.getTargetType(typeId); BuildTargetLoader<?> loader = type != null ? type.createLoader(model) : null; while (targetCount-- > 0) { final String id = IOUtil.readString(in); boolean loaded = false; if (loader != null) { BuildTarget<?> target = loader.createTarget(id); if (target != null) { getDelta(target).load(in, target, buildRootIndex); myInitialScanPerformed.add(target); loaded = true; } } if (!loaded) { LOG.info("Skipping unknown target (typeId=" + typeId + ", type=" + type + ", id=" + id + ")"); FilesDelta.skip(in); } } } }
public synchronized void save() { try { FileUtil.createParentDirs(myTargetsFile); DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(myTargetsFile))); try { output.writeInt(0); output.writeInt(myTargetIds.size()); for (Map.Entry<BuildTarget<?>, Integer> entry : myTargetIds.entrySet()) { IOUtil.writeString(entry.getKey().getId(), output); output.writeInt(entry.getValue()); } } finally { output.close(); } } catch (IOException e) { LOG.info("Cannot save " + myTargetType.getTypeId() + " targets data: " + e.getMessage(), e); } }
public void testReplaceWithEqualButNotSameKey() throws IOException { File file = FileUtil.createTempFile(getTestDirectoryName(), null); ObjectObjectPersistentMultiMaplet<String, IntValueStreamable> maplet = new ObjectObjectPersistentMultiMaplet<String, IntValueStreamable>(file, new CaseInsensitiveEnumeratorStringDescriptor(), new IntValueExternalizer(), COLLECTION_FACTORY); try { maplet.put("a", new IntValueStreamable(1)); assertEquals(1, assertOneElement(maplet.get("a")).value); maplet.replace("A", Collections.singletonList(new IntValueStreamable(2))); assertEquals(2, assertOneElement(maplet.get("a")).value); } finally { maplet.close(); IOUtil.deleteAllFilesStartingWith(file); } }
public void save() throws IOException { final DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(myFile))); try { output.writeInt(VERSION); output.writeInt(myCompilerVersion); output.writeInt(myTarget2Id.size()); for (Map.Entry<String, Integer> entry : myTarget2Id.entrySet()) { IOUtil.writeString(entry.getKey(), output); output.writeInt(entry.getValue()); } } finally { output.close(); } }
public VcsLogHashMapImpl(@NotNull Project project, @NotNull Map<VirtualFile, VcsLogProvider> logProviders) throws IOException { cleanupOldNaming(project, logProviders); String logId = calcLogId(project, logProviders); final File mapFile = new File(LOG_CACHE_APP_DIR, logId + "." + VERSION); if (!mapFile.exists()) { IOUtil.deleteAllFilesStartingWith(new File(LOG_CACHE_APP_DIR, logId)); } Disposer.register(project, this); myPersistentEnumerator = IOUtil.openCleanOrResetBroken(new ThrowableComputable<PersistentEnumerator<Hash>, IOException>() { @Override public PersistentEnumerator<Hash> compute() throws IOException { return new PersistentEnumerator<Hash>(mapFile, new MyHashKeyDescriptor(), Page.PAGE_SIZE); } }, mapFile); }
@Nullable public static String getFrameworkIdOfBuildFile(VirtualFile file) { if (file instanceof NewVirtualFile) { final DataInputStream is = FRAMEWORK_FILE_ATTRIBUTE.readAttribute(file); if (is != null) { try { try { if (is.available() == 0) { return null; } return IOUtil.readString(is); } finally { is.close(); } } catch (IOException e) { LOG.error(file.getPath(), e); } } return ""; } return file.getUserData(FRAMEWORK_FILE_MARKER); }
private static void forceBuildFile(VirtualFile file, @Nullable String value) { if (file instanceof NewVirtualFile) { final DataOutputStream os = FRAMEWORK_FILE_ATTRIBUTE.writeAttribute(file); try { try { IOUtil.writeString(StringUtil.notNullize(value), os); } finally { os.close(); } } catch (IOException e) { LOG.error(e); } } else { file.putUserData(FRAMEWORK_FILE_MARKER, value); } }
@Nullable protected SubstringWrapper[] internParts(String path, boolean forAddition) { int start = 0; boolean asBytes = forAddition && IOUtil.isAscii(path); List<SubstringWrapper> key = new ArrayList<SubstringWrapper>(); SubstringWrapper flyweightKey = new SubstringWrapper(); while (start < path.length()) { flyweightKey.findSubStringUntilNextSeparator(path, start); SubstringWrapper interned = myInternMap.get(flyweightKey); if (interned == null) { if (!forAddition) { return null; } myInternMap.add(interned = flyweightKey.createPersistentCopy(asBytes)); } key.add(interned); start += flyweightKey.len; } return key.toArray(new SubstringWrapper[key.size()]); }
private void thingsWentWrongLetsReinitialize(IOException e) { try { if (myMap != null) { try { myMap.close(); } catch (IOException ignore) { } IOUtil.deleteAllFilesStartingWith(myFile); } myMap = initializeMap(); LOG.error("Repaired after crash", e); } catch (IOException e1) { LOG.error("Cannot repair", e1); myMap = null; } }
@NotNull @Override public DataExternalizer<XsdNamespaceBuilder> getValueExternalizer() { return new DataExternalizer<XsdNamespaceBuilder>() { @Override public void save(@NotNull DataOutput out, XsdNamespaceBuilder value) throws IOException { IOUtil.writeUTF(out, value.getNamespace() == null ? "" : value.getNamespace()); IOUtil.writeUTF(out, value.getVersion() == null ? "" : value.getVersion()); writeList(out, value.getTags()); writeList(out, value.getRootTags()); } @Override public XsdNamespaceBuilder read(@NotNull DataInput in) throws IOException { return new XsdNamespaceBuilder(IOUtil.readUTF(in), IOUtil.readUTF(in), readList(in), readList(in)); } }; }
@Nullable @Override public Set<MyResourceInfo> read(@NotNull DataInput in) throws IOException { final int size = DataInputOutputUtil.readINT(in); if (size < 0 || size > 65535) { // Something is very wrong; trigger an index rebuild throw new IOException("Corrupt Index: Size " + size); } if (size == 0) { return Collections.emptySet(); } final Set<MyResourceInfo> result = Sets.newHashSetWithExpectedSize(size); for (int i = 0; i < size; i++) { final String type = IOUtil.readUTF(in); final String name = IOUtil.readUTF(in); final String context = IOUtil.readUTF(in); final int offset = DataInputOutputUtil.readINT(in); result.add(new MyResourceInfo(new ResourceEntry(type, name, context), offset)); } return result; }
@Override public boolean visitFile(VirtualFile file) { file.putUserData(MODIFICATION_DATE_KEY, null); if(file instanceof NewVirtualFile) { final DataOutputStream os = MODIFICATION_STAMP_FILE_ATTRIBUTE.writeAttribute(file); try { try { IOUtil.writeString(StringUtil.notNullize("0"), os); } finally { os.close(); } } catch(IOException e) { // Ignore it but we might need to throw an exception String message = e.getMessage(); } } return recursive; }
public static void setModificationStamp(VirtualFile file) { // Store it in memory first if(file != null) { file.putUserData(Util.MODIFICATION_DATE_KEY, file.getTimeStamp()); if(file instanceof NewVirtualFile) { final DataOutputStream os = MODIFICATION_STAMP_FILE_ATTRIBUTE.writeAttribute(file); try { try { IOUtil.writeString(StringUtil.notNullize(file.getTimeStamp() + ""), os); } finally { os.close(); } } catch(IOException e) { // Ignore it but we might need to throw an exception String message = e.getMessage(); } } } }
public void save(DataOutput out) throws IOException { out.writeInt(myDeletedPaths.size()); synchronized (myDeletedPaths) { for (String path : myDeletedPaths) { IOUtil.writeString(path, out); } } synchronized (myFilesToRecompile) { out.writeInt(myFilesToRecompile.size()); for (Map.Entry<BuildRootDescriptor, Set<File>> entry : myFilesToRecompile.entrySet()) { IOUtil.writeString(entry.getKey().getRootId(), out); final Set<File> files = entry.getValue(); out.writeInt(files.size()); for (File file : files) { IOUtil.writeString(FileUtil.toSystemIndependentName(file.getPath()), out); } } } }
@NotNull public Stub deserialize(@NotNull InputStream stream) throws IOException, SerializerNotFoundException { FileLocalStringEnumerator storage = new FileLocalStringEnumerator(); StubInputStream inputStream = new StubInputStream(stream, storage); final int size = DataInputOutputUtil.readINT(inputStream); byte[] buffer = IOUtil.allocReadWriteUTFBuffer(); int i = 1; while(i <= size) { String s = myStringInterner.get(IOUtil.readUTFFast(buffer, inputStream)); storage.myStrings.add(s); storage.myEnumerates.put(s, i); ++i; } return deserialize(inputStream, null); }
private void thingsWentWrongLetsReinitialize(IOException e, String message) { try { if (myMap != null) { try { myMap.close(); } catch (IOException ignore) { } IOUtil.deleteAllFilesStartingWith(myFile); } myMap = initializeMap(); LOG.error(message, e); } catch (IOException e1) { LOG.error("Cannot repair", e1); myMap = null; } }
static void initContentHashesEnumerator() throws IOException { if (ourHashesWithFileType != null) return; synchronized (ContentHashesSupport.class) { if (ourHashesWithFileType != null) return; final File hashEnumeratorFile = new File(IndexInfrastructure.getPersistentIndexRoot(), "hashesWithFileType"); try { ContentHashesUtil.HashEnumerator hashEnumerator = new ContentHashesUtil.HashEnumerator(hashEnumeratorFile, null); FlushingDaemon.everyFiveSeconds(ContentHashesSupport::flushContentHashes); ShutDownTracker.getInstance().registerShutdownTask(ContentHashesSupport::flushContentHashes); ourHashesWithFileType = hashEnumerator; } catch (IOException ex) { IOUtil.deleteAllFilesStartingWith(hashEnumeratorFile); throw ex; } } }
public void load(DataInput in, @NotNull BuildTarget<?> target, BuildRootIndex buildRootIndex) throws IOException { lockData(); try { myDeletedPaths.clear(); int deletedCount = in.readInt(); while (deletedCount-- > 0) { myDeletedPaths.add(IOUtil.readString(in)); } myFilesToRecompile.clear(); int recompileCount = in.readInt(); while (recompileCount-- > 0) { String rootId = IOUtil.readString(in); BuildRootDescriptor descriptor = target.findRootDescriptor(rootId, buildRootIndex); Set<File> files; if (descriptor != null) { files = myFilesToRecompile.get(descriptor); if (files == null) { files = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY); myFilesToRecompile.put(descriptor, files); } } else { LOG.debug("Cannot find root by " + rootId + ", delta will be skipped"); files = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY); } int filesCount = in.readInt(); while (filesCount-- > 0) { final File file = new File(IOUtil.readString(in)); if (Utils.IS_TEST_MODE) { LOG.info("Loaded " + file.getPath()); } files.add(file); } } } finally { unlockData(); } }
public static void skip(DataInput in) throws IOException { int deletedCount = in.readInt(); while (deletedCount-- > 0) { IOUtil.readString(in); } int recompiledCount = in.readInt(); while (recompiledCount-- > 0) { IOUtil.readString(in); int filesCount = in.readInt(); while (filesCount-- > 0) { IOUtil.readString(in); } } }
@Override public void save(@NotNull DataOutput out, List<SourcePathAndRootIndex> value) throws IOException { for (SourcePathAndRootIndex pair : value) { IOUtil.writeUTF(out, pair.myPath); out.writeInt(pair.getRootIndex()); } }
@Override public List<SourcePathAndRootIndex> read(@NotNull DataInput in) throws IOException { List<SourcePathAndRootIndex> result = new SmartList<SourcePathAndRootIndex>(); final DataInputStream stream = (DataInputStream)in; while (stream.available() > 0) { final String path = IOUtil.readUTF(stream); final int index = stream.readInt(); result.add(new SourcePathAndRootIndex(path, index)); } return result; }
private boolean load() { if (!myTargetsFile.exists()) { return false; } try { DataInputStream input = new DataInputStream(new BufferedInputStream(new FileInputStream(myTargetsFile))); try { input.readInt();//reserved for version int size = input.readInt(); BuildTargetLoader<?> loader = myTargetType.createLoader(myTargetsState.getModel()); while (size-- > 0) { String stringId = IOUtil.readString(input); int intId = input.readInt(); myTargetsState.markUsedId(intId); BuildTarget<?> target = loader.createTarget(stringId); if (target != null) { myTargetIds.put(target, intId); } else { LOG.info("Unknown " + myTargetType.getTypeId() + " target: " + stringId); } } return true; } finally { input.close(); } } catch (IOException e) { LOG.info("Cannot load " + myTargetType.getTypeId() + " targets data: " + e.getMessage(), e); return false; } }
public Collection<String> read(@NotNull DataInput in) throws IOException { final Set<String> result = new THashSet<String>(FileUtil.PATH_HASHING_STRATEGY); final DataInputStream stream = (DataInputStream)in; while (stream.available() > 0) { final String str = IOUtil.readUTF(stream); result.add(str); } return result; }
@Override public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement element) { if (!element.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return false; final Pair<PsiElement, Handler> pair = findHandler(element); if (pair == null) return false; String text = pair.first.getText(); return !IOUtil.isAscii(text); }
@Override public void save(@NotNull DataOutput out, VirtualFileSetState value) throws IOException { final Map<String, Long> dependencies = value.myTimestamps; out.writeInt(dependencies.size()); for (Map.Entry<String, Long> entry : dependencies.entrySet()) { IOUtil.writeUTF(out, entry.getKey()); out.writeLong(entry.getValue()); } }
@Override public VirtualFileSetState read(@NotNull DataInput in) throws IOException { final VirtualFileSetState state = new VirtualFileSetState(); int size = in.readInt(); while (size-- > 0) { final String url = IOUtil.readUTF(in); final long timestamp = in.readLong(); state.myTimestamps.put(url, timestamp); } return state; }
@Override public void save(@NotNull DataOutput out, VirtualFileWithDependenciesState value) throws IOException { out.writeLong(value.mySourceTimestamp); final Map<String, Long> dependencies = value.myDependencies; out.writeInt(dependencies.size()); for (Map.Entry<String, Long> entry : dependencies.entrySet()) { IOUtil.writeUTF(out, entry.getKey()); out.writeLong(entry.getValue()); } }
@Override public VirtualFileWithDependenciesState read(@NotNull DataInput in) throws IOException { final VirtualFileWithDependenciesState state = new VirtualFileWithDependenciesState(in.readLong()); int size = in.readInt(); while (size-- > 0) { final String url = IOUtil.readUTF(in); final long timestamp = in.readLong(); state.myDependencies.put(url, timestamp); } return state; }
public void save(DataOutput out) throws IOException { final Set<Map.Entry<String, Long>> entries = myDependencies.entrySet(); out.writeInt(entries.size()); for (Map.Entry<String, Long> entry : entries) { IOUtil.writeString(entry.getKey(), out); out.writeLong(entry.getValue().longValue()); } }