Java 类com.intellij.openapi.vfs.newvfs.FileAttribute 实例源码

项目:intellij-ce-playground    文件:FSRecords.java   
@NotNull
public static DataOutputStream writeAttribute(final int fileId, @NotNull FileAttribute att) {
  DataOutputStream stream = new AttributeOutputStream(fileId, att);
  if (att.isVersioned()) {
    try {
      DataInputOutputUtil.writeINT(stream, att.getVersion());
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
  return stream;
}
项目:consulo    文件:FSRecords.java   
@Nonnull
public static DataOutputStream writeAttribute(final int fileId, @Nonnull FileAttribute att) {
  DataOutputStream stream = new AttributeOutputStream(fileId, att);
  if (att.isVersioned()) {
    try {
      DataInputOutputUtil.writeINT(stream, att.getVersion());
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
  return stream;
}
项目:intellij-ce-playground    文件:FSRecords.java   
@Nullable
private static DataInputStream readAttribute(int fileId, FileAttribute attribute) throws IOException {
  checkFileIsValid(fileId);

  int recordId = getAttributeRecordId(fileId);
  if (recordId == 0) return null;
  int encodedAttrId = DbConnection.getAttributeId(attribute.getId());

  Storage storage = getAttributesStorage();

  DataInputStream attrRefs = storage.readStream(recordId);
  int page = 0;

  try {
    if (bulkAttrReadSupport) skipRecordHeader(attrRefs, DbConnection.RESERVED_ATTR_ID, fileId);

    while (attrRefs.available() > 0) {
      final int attIdOnPage = DataInputOutputUtil.readINT(attrRefs);
      final int attrAddressOrSize = DataInputOutputUtil.readINT(attrRefs);

      if (attIdOnPage != encodedAttrId) {
        if (inlineAttributes && attrAddressOrSize < MAX_SMALL_ATTR_SIZE) {
          attrRefs.skipBytes(attrAddressOrSize);
        }
      } else {
        if (inlineAttributes && attrAddressOrSize < MAX_SMALL_ATTR_SIZE) {
          byte[] b = new byte[attrAddressOrSize];
          attrRefs.readFully(b);
          return new DataInputStream(new ByteArrayInputStream(b));
        }
        page = inlineAttributes ? attrAddressOrSize - MAX_SMALL_ATTR_SIZE : attrAddressOrSize;
        break;
      }
    }
  }
  finally {
    attrRefs.close();
  }

  if (page == 0) {
    return null;
  }
  DataInputStream stream = getAttributesStorage().readStream(page);
  if (bulkAttrReadSupport) skipRecordHeader(stream, encodedAttrId, fileId);
  return stream;
}
项目:intellij-ce-playground    文件:FSRecords.java   
private static int findAttributePage(int fileId, FileAttribute attr, boolean toWrite) throws IOException {
  checkFileIsValid(fileId);

  int recordId = getAttributeRecordId(fileId);
  int encodedAttrId = DbConnection.getAttributeId(attr.getId());
  boolean directoryRecord = false;

  Storage storage = getAttributesStorage();

  if (recordId == 0) {
    if (!toWrite) return 0;

    recordId = storage.createNewRecord();
    setAttributeRecordId(fileId, recordId);
    directoryRecord = true;
  }
  else {
    DataInputStream attrRefs = storage.readStream(recordId);

    try {
      if (bulkAttrReadSupport) skipRecordHeader(attrRefs, DbConnection.RESERVED_ATTR_ID, fileId);

      while (attrRefs.available() > 0) {
        final int attIdOnPage = DataInputOutputUtil.readINT(attrRefs);
        final int attrAddressOrSize = DataInputOutputUtil.readINT(attrRefs);

        if (attIdOnPage == encodedAttrId) {
          if (inlineAttributes) {
            return attrAddressOrSize < MAX_SMALL_ATTR_SIZE ? -recordId : attrAddressOrSize - MAX_SMALL_ATTR_SIZE;
          } else {
            return attrAddressOrSize;
          }
        } else {
          if (inlineAttributes && attrAddressOrSize < MAX_SMALL_ATTR_SIZE) {
            attrRefs.skipBytes(attrAddressOrSize);
          }
        }

      }
    }
    finally {
      attrRefs.close();
    }
  }

  if (toWrite) {
    Storage.AppenderStream appender = storage.appendStream(recordId);
    if (bulkAttrReadSupport) {
      if (directoryRecord) {
        DataInputOutputUtil.writeINT(appender, DbConnection.RESERVED_ATTR_ID);
        DataInputOutputUtil.writeINT(appender, fileId);
      }
    }

    DataInputOutputUtil.writeINT(appender, encodedAttrId);
    int attrAddress = storage.createNewRecord();
    DataInputOutputUtil.writeINT(appender, inlineAttributes ? attrAddress + MAX_SMALL_ATTR_SIZE : attrAddress);
    DbConnection.REASONABLY_SMALL.myAttrPageRequested = true;
    try {
      appender.close();
    } finally {
      DbConnection.REASONABLY_SMALL.myAttrPageRequested = false;
    }
    return attrAddress;
  }

  return 0;
}
项目:intellij-ce-playground    文件:FSRecords.java   
private AttributeOutputStream(final int fileId, @NotNull FileAttribute attribute) {
  super(new BufferExposingByteArrayOutputStream());
  myFileId = fileId;
  myAttribute = attribute;
}
项目:consulo    文件:CompilerServerManagingFSImpl.java   
@Nullable
@Override
public DataInputStream readAttribute(@Nonnull VirtualFile file, @Nonnull FileAttribute att) {
  return new DataInputStream(new ByteArrayInputStream(new byte[100]));
}
项目:consulo    文件:CompilerServerManagingFSImpl.java   
@Nonnull
@Override
public DataOutputStream writeAttribute(@Nonnull VirtualFile file, @Nonnull FileAttribute att) {
  return new DataOutputStream(new ByteArrayOutputStream(100));
}
项目:consulo    文件:FSRecords.java   
@Nullable
private static DataInputStream readAttribute(int fileId, FileAttribute attribute) throws IOException {
  checkFileIsValid(fileId);

  int recordId = getAttributeRecordId(fileId);
  if (recordId == 0) return null;
  int encodedAttrId = DbConnection.getAttributeId(attribute.getId());

  Storage storage = getAttributesStorage();

  DataInputStream attrRefs = storage.readStream(recordId);
  int page = 0;

  try {
    if (bulkAttrReadSupport) skipRecordHeader(attrRefs, DbConnection.RESERVED_ATTR_ID, fileId);

    while (attrRefs.available() > 0) {
      final int attIdOnPage = DataInputOutputUtil.readINT(attrRefs);
      final int attrAddressOrSize = DataInputOutputUtil.readINT(attrRefs);

      if (attIdOnPage != encodedAttrId) {
        if (inlineAttributes && attrAddressOrSize < MAX_SMALL_ATTR_SIZE) {
          attrRefs.skipBytes(attrAddressOrSize);
        }
      } else {
        if (inlineAttributes && attrAddressOrSize < MAX_SMALL_ATTR_SIZE) {
          byte[] b = new byte[attrAddressOrSize];
          attrRefs.readFully(b);
          return new DataInputStream(new ByteArrayInputStream(b));
        }
        page = inlineAttributes ? attrAddressOrSize - MAX_SMALL_ATTR_SIZE : attrAddressOrSize;
        break;
      }
    }
  }
  finally {
    attrRefs.close();
  }

  if (page == 0) {
    return null;
  }
  DataInputStream stream = getAttributesStorage().readStream(page);
  if (bulkAttrReadSupport) skipRecordHeader(stream, encodedAttrId, fileId);
  return stream;
}
项目:consulo    文件:FSRecords.java   
private static int findAttributePage(int fileId, FileAttribute attr, boolean toWrite) throws IOException {
  checkFileIsValid(fileId);

  int recordId = getAttributeRecordId(fileId);
  int encodedAttrId = DbConnection.getAttributeId(attr.getId());
  boolean directoryRecord = false;

  Storage storage = getAttributesStorage();

  if (recordId == 0) {
    if (!toWrite) return 0;

    recordId = storage.createNewRecord();
    setAttributeRecordId(fileId, recordId);
    directoryRecord = true;
  }
  else {
    DataInputStream attrRefs = storage.readStream(recordId);

    try {
      if (bulkAttrReadSupport) skipRecordHeader(attrRefs, DbConnection.RESERVED_ATTR_ID, fileId);

      while (attrRefs.available() > 0) {
        final int attIdOnPage = DataInputOutputUtil.readINT(attrRefs);
        final int attrAddressOrSize = DataInputOutputUtil.readINT(attrRefs);

        if (attIdOnPage == encodedAttrId) {
          if (inlineAttributes) {
            return attrAddressOrSize < MAX_SMALL_ATTR_SIZE ? -recordId : attrAddressOrSize - MAX_SMALL_ATTR_SIZE;
          } else {
            return attrAddressOrSize;
          }
        } else {
          if (inlineAttributes && attrAddressOrSize < MAX_SMALL_ATTR_SIZE) {
            attrRefs.skipBytes(attrAddressOrSize);
          }
        }

      }
    }
    finally {
      attrRefs.close();
    }
  }

  if (toWrite) {
    Storage.AppenderStream appender = storage.appendStream(recordId);
    if (bulkAttrReadSupport) {
      if (directoryRecord) {
        DataInputOutputUtil.writeINT(appender, DbConnection.RESERVED_ATTR_ID);
        DataInputOutputUtil.writeINT(appender, fileId);
      }
    }

    DataInputOutputUtil.writeINT(appender, encodedAttrId);
    int attrAddress = storage.createNewRecord();
    DataInputOutputUtil.writeINT(appender, inlineAttributes ? attrAddress + MAX_SMALL_ATTR_SIZE : attrAddress);
    DbConnection.REASONABLY_SMALL.myAttrPageRequested = true;
    try {
      appender.close();
    } finally {
      DbConnection.REASONABLY_SMALL.myAttrPageRequested = false;
    }
    return attrAddress;
  }

  return 0;
}
项目:consulo    文件:FSRecords.java   
private AttributeOutputStream(final int fileId, @Nonnull FileAttribute attribute) {
  super(new BufferExposingByteArrayOutputStream());
  myFileId = fileId;
  myAttribute = attribute;
}
项目:consulo    文件:VirtualFileGistImpl.java   
@Nullable
@Override
protected FileAttribute create(Pair<String, Integer> key) {
  return new FileAttribute(key.first, key.second, false);
}
项目:consulo    文件:VirtualFileGistImpl.java   
private FileAttribute getFileAttribute(Project project) {
  synchronized (ourAttributes) {
    return ourAttributes.get(Pair.create(myId + project.getLocationHash(), myVersion + ourInternalVersion));
  }
}