com.intellij.util.io.IOUtil Java Examples

The following examples show how to use com.intellij.util.io.IOUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileUtil.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 6 votes vote down vote up
public static String getParams(VirtualFile file) {
    String userData = file.getUserData(MY_KEY);
    if (userData != null) {
        return userData;
    }

    if (!(file instanceof NewVirtualFile)) {
        return "{}";
    }

    try (DataInputStream is = QUERY_PARAMS_FILE_ATTRIBUTE.readAttribute(file)) {
        if (is == null || is.available() <= 0) {
            return "{}";
        }

        String attributeData = IOUtil.readString(is);
        if (attributeData == null) {
            return "{}";
        } else {
            file.putUserData(MY_KEY, attributeData);
            return attributeData;
        }
    } catch (IOException e) {
        return "{}";
    }
}
 
Example #2
Source File: Util.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: ContentHashesSupport.java    From consulo with Apache License 2.0 6 votes vote down vote up
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;
    }
  }
}
 
Example #4
Source File: Util.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
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();
            }
        }
    }
}
 
Example #5
Source File: SerializationManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void repairNameStorage() {
  if (myNameStorageCrashed.getAndSet(false)) {
    try {
      LOG.info("Name storage is repaired");
      if (myNameStorage != null) {
        myNameStorage.close();
      }

      StubSerializationHelper prevHelper = myStubSerializationHelper;
      if (myUnmodifiable) {
        LOG.error("Data provided by unmodifiable serialization manager can be invalid after repair");
      }

      IOUtil.deleteAllFilesStartingWith(myFile);
      myNameStorage = new PersistentStringEnumerator(myFile, true);
      myStubSerializationHelper = new StubSerializationHelper(myNameStorage, myUnmodifiable, this);
      myStubSerializationHelper.copyFrom(prevHelper);
    }
    catch (IOException e) {
      LOG.info(e);
      nameStorageCrashed();
    }
  }
}
 
Example #6
Source File: TestStateStorage.java    From consulo with Apache License 2.0 6 votes vote down vote up
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;
  }
}
 
Example #7
Source File: PathInterner.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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()]);
}
 
Example #8
Source File: ForcedBuildFileAttribute.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #9
Source File: ForcedBuildFileAttribute.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #10
Source File: TypoTolerantMatcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
private int indexOfIgnoreCase(int fromIndex, int patternIndex, @Nonnull ErrorState errorState) {
  char p = charAt(patternIndex, errorState);
  if (isAsciiName && IOUtil.isAscii(p)) {
    int i = indexIgnoringCaseAscii(fromIndex, patternIndex, p);
    if (i != -1) return i;

    if (myAllowTypos) {
      int leftMiss = indexIgnoringCaseAscii(fromIndex, patternIndex, leftMiss(p));
      if (leftMiss != -1) return leftMiss;

      int rightMiss = indexIgnoringCaseAscii(fromIndex, patternIndex, rightMiss(p));
      if (rightMiss != -1) return rightMiss;
    }

    return -1;
  }
  return StringUtil.indexOfIgnoreCase(myName, p, fromIndex);
}
 
Example #11
Source File: GenericCompilerPersistentData.java    From consulo with Apache License 2.0 6 votes vote down vote up
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();
  }
}
 
Example #12
Source File: FileUtil.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
public static void setParams(VirtualFile file, String params) {
    file.putUserData(MY_KEY, params);
    if (file instanceof NewVirtualFile) {
        try (DataOutputStream os = QUERY_PARAMS_FILE_ATTRIBUTE.writeAttribute(file)) {
            IOUtil.writeString(StringUtil.notNullize(params), os);
        } catch (IOException e) {
        }
    }
}
 
Example #13
Source File: FileLocalStringEnumerator.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void readEnumeratedStrings(@Nonnull FileLocalStringEnumerator enumerator, @Nonnull DataInput stream, @Nonnull UnaryOperator<String> interner) throws IOException {
  final int numberOfStrings = DataInputOutputUtil.readINT(stream);
  byte[] buffer = IOUtil.allocReadWriteUTFBuffer();
  enumerator.myStrings.ensureCapacity(numberOfStrings);

  int i = 0;
  while (i < numberOfStrings) {
    String s = interner.apply(IOUtil.readUTFFast(buffer, stream));
    enumerator.myStrings.add(s);
    ++i;
  }
}
 
Example #14
Source File: VcsLogStorageImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public VcsRef read(@Nonnull DataInput in) throws IOException {
  CommitId commitId = myCommitIdKeyDescriptor.read(in);
  if (commitId == null) throw new IOException("Can not read commit id for reference");
  String name = IOUtil.readUTF(in);
  VcsRefType type = myLogProviders.get(commitId.getRoot()).getReferenceManager().deserialize(in);
  return new VcsRefImpl(commitId.getHash(), name, type, commitId.getRoot());
}
 
Example #15
Source File: MinusculeMatcherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private int indexOfIgnoreCase(String name, int fromIndex, char p, int patternIndex, boolean isAsciiName) {
  if (isAsciiName && IOUtil.isAscii(p)) {
    char pUpper = toUpperCase[patternIndex];
    char pLower = toLowerCase[patternIndex];
    for (int i = fromIndex; i < name.length(); i++) {
      char c = name.charAt(i);
      if (c == p || toUpperAscii(c) == pUpper || toLowerAscii(c) == pLower) {
        return i;
      }
    }
    return -1;
  }
  return StringUtil.indexOfIgnoreCase(name, p, fromIndex);
}
 
Example #16
Source File: ArtifactPackagingItemExternalizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public ArtifactPackagingItemOutputState read(DataInput in) throws IOException {
  int size = in.readInt();
  SmartList<Pair<String, Long>> destinations = new SmartList<Pair<String, Long>>();
  while (size-- > 0) {
    String path = IOUtil.readUTF(in);
    long outputTimestamp = in.readLong();
    destinations.add(Pair.create(path, outputTimestamp));
  }
  return new ArtifactPackagingItemOutputState(destinations);
}
 
Example #17
Source File: Util.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public static long getModificationStamp(VirtualFile file) {
    long ret = -1;
    Long temporary = file.getUserData(Util.MODIFICATION_DATE_KEY);
    if(temporary == null || temporary <= 0) {
        if(file instanceof NewVirtualFile) {
            final DataInputStream is = MODIFICATION_STAMP_FILE_ATTRIBUTE.readAttribute(file);
            if(is != null) {
                try {
                    try {
                        if(is.available() > 0) {
                            String value = IOUtil.readString(is);
                            ret = convertToLong(value, ret);
                            if(ret > 0) {
                                file.putUserData(Util.MODIFICATION_DATE_KEY, ret);
                            }
                        }
                    } finally {
                        is.close();
                    }
                } catch(IOException e) {
                    // Ignore it but we might need to throw an exception
                    String message = e.getMessage();
                }
            }
        }
    } else {
        ret = temporary;
    }
    return ret;
}
 
Example #18
Source File: VirtualFileWithDependenciesState.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public VirtualFileWithDependenciesState read(@Nonnull 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;
}
 
Example #19
Source File: HaxeClassInfoListExternalizer.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void save(@NotNull DataOutput out, List<HaxeClassInfo> value) throws IOException {
  out.writeInt(value.size());
  for (HaxeClassInfo classInfo : value) {
    final HaxeComponentType haxeComponentType = classInfo.getType();
    final int key = haxeComponentType == null ? -1 : haxeComponentType.getKey();
    out.writeInt(key);
    IOUtil.writeUTFFast(buffer.get(), out, classInfo.getValue());
  }
}
 
Example #20
Source File: HaxeClassInfoListExternalizer.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public List<HaxeClassInfo> read(@NotNull DataInput in) throws IOException {
  final int size = in.readInt();
  final List<HaxeClassInfo> result = new ArrayList<HaxeClassInfo>(size);
  for (int i = 0; i < size; ++i) {
    final int key = in.readInt();
    final String value = IOUtil.readUTFFast(buffer.get(), in);
    result.add(new HaxeClassInfo(value, HaxeComponentType.valueOf(key)));
  }
  return result;
}
 
Example #21
Source File: VirtualFileWithDependenciesState.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void save(@Nonnull 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());
  }
}
 
Example #22
Source File: ArtifactPackagingItemExternalizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void save(DataOutput out, ArtifactPackagingItemOutputState value) throws IOException {
  out.writeInt(value.myDestinations.size());
  for (Pair<String, Long> pair : value.myDestinations) {
    IOUtil.writeUTF(out, pair.getFirst());
    out.writeLong(pair.getSecond());
  }
}
 
Example #23
Source File: HaxeClassInfoExternalizer.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void save(@NotNull DataOutput out, HaxeClassInfo classInfo) throws IOException {
  IOUtil.writeUTFFast(buffer.get(), out, classInfo.getValue());
  final HaxeComponentType haxeComponentType = classInfo.getType();
  final int key = haxeComponentType == null ? -1 : haxeComponentType.getKey();
  out.writeInt(key);
}
 
Example #24
Source File: CopyingCompiler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public ValidityState createValidityState(DataInput in) throws IOException {
  return new DestinationFileInfo(IOUtil.readString(in), true);
}
 
Example #25
Source File: HaxeClassInfoListExternalizer.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
protected byte[] initialValue() {
  return IOUtil.allocReadWriteUTFBuffer();
}
 
Example #26
Source File: TestStateStorage.java    From consulo with Apache License 2.0 4 votes vote down vote up
private PersistentHashMap<String, Record> initializeMap() throws IOException {
  return IOUtil.openCleanOrResetBroken(getComputable(myFile), myFile);
}
 
Example #27
Source File: HaxeClassInfoExternalizer.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
protected byte[] initialValue() {
  return IOUtil.allocReadWriteUTFBuffer();
}
 
Example #28
Source File: HaxeClassInfoExternalizer.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
public HaxeClassInfo read(@NotNull DataInput in) throws IOException {
  final String value = IOUtil.readUTFFast(buffer.get(), in);
  final int key = in.readInt();
  return new HaxeClassInfo(value, HaxeComponentType.valueOf(key));
}
 
Example #29
Source File: VcsLogStorageImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void save(@Nonnull DataOutput out, @Nonnull VcsRef value) throws IOException {
  myCommitIdKeyDescriptor.save(out, new CommitId(value.getCommitHash(), value.getRoot()));
  IOUtil.writeUTF(out, value.getName());
  myLogProviders.get(value.getRoot()).getReferenceManager().serialize(out, value.getType());
}
 
Example #30
Source File: CopyingCompiler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void save(DataOutput out) throws IOException {
  IOUtil.writeString(destinationPath, out);
}