This commit is contained in:
Alexey Kudravtsev
2019-01-21 13:42:51 +03:00
parent 61273fe7de
commit 1bf3e249a2
3 changed files with 68 additions and 53 deletions
@@ -95,7 +95,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@Override
public boolean areChildrenLoaded(@NotNull final VirtualFile dir) {
public boolean areChildrenLoaded(@NotNull VirtualFile dir) {
return areChildrenLoaded(getFileId(dir));
}
@@ -124,13 +124,13 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@Override
public boolean wereChildrenAccessed(@NotNull final VirtualFile dir) {
public boolean wereChildrenAccessed(@NotNull VirtualFile dir) {
return FSRecords.wereChildrenAccessed(getFileId(dir));
}
@Override
@NotNull
public String[] list(@NotNull final VirtualFile file) {
public String[] list(@NotNull VirtualFile file) {
int id = getFileId(file);
FSRecords.NameId[] nameIds = FSRecords.listAll(id);
@@ -156,7 +156,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@NotNull
private static FSRecords.NameId[] persistAllChildren(@NotNull final VirtualFile file, final int id, @NotNull FSRecords.NameId[] current) {
private static FSRecords.NameId[] persistAllChildren(@NotNull VirtualFile file, int id, @NotNull FSRecords.NameId[] current) {
final NewVirtualFileSystem fs = replaceWithNativeFS(getDelegate(file));
String[] delegateNames = VfsUtil.filterNames(fs.list(file));
@@ -209,19 +209,19 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
return nameIds;
}
private static boolean areChildrenLoaded(final int parentId) {
private static boolean areChildrenLoaded(int parentId) {
return BitUtil.isSet(FSRecords.getFlags(parentId), CHILDREN_CACHED_FLAG);
}
@Override
@Nullable
public DataInputStream readAttribute(@NotNull final VirtualFile file, @NotNull final FileAttribute att) {
public DataInputStream readAttribute(@NotNull VirtualFile file, @NotNull FileAttribute att) {
return FSRecords.readAttributeWithLock(getFileId(file), att);
}
@Override
@NotNull
public DataOutputStream writeAttribute(@NotNull final VirtualFile file, @NotNull final FileAttribute att) {
public DataOutputStream writeAttribute(@NotNull VirtualFile file, @NotNull FileAttribute att) {
return FSRecords.writeAttribute(getFileId(file), att);
}
@@ -250,7 +250,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@Override
public int getModificationCount(@NotNull final VirtualFile file) {
public int getModificationCount(@NotNull VirtualFile file) {
return FSRecords.getModCount(getFileId(file));
}
@@ -273,8 +273,8 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
return FSRecords.getModCount();
}
private static boolean writeAttributesToRecord(final int id,
final int parentId,
private static boolean writeAttributesToRecord(int id,
int parentId,
@NotNull VirtualFile file,
@NotNull NewVirtualFileSystem fs,
@NotNull FileAttributes attributes) {
@@ -300,7 +300,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@Override
public boolean isDirectory(@NotNull final VirtualFile file) {
public boolean isDirectory(@NotNull VirtualFile file) {
return isDirectory(getFileAttributes(getFileId(file)));
}
@@ -309,17 +309,17 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@Override
public boolean exists(@NotNull final VirtualFile fileOrDirectory) {
public boolean exists(@NotNull VirtualFile fileOrDirectory) {
return ((VirtualFileWithId)fileOrDirectory).getId() > 0;
}
@Override
public long getTimeStamp(@NotNull final VirtualFile file) {
public long getTimeStamp(@NotNull VirtualFile file) {
return FSRecords.getTimestamp(getFileId(file));
}
@Override
public void setTimeStamp(@NotNull final VirtualFile file, final long modStamp) throws IOException {
public void setTimeStamp(@NotNull VirtualFile file, long modStamp) throws IOException {
final int id = getFileId(file);
FSRecords.setTimestamp(id, modStamp);
getDelegate(file).setTimeStamp(file, modStamp);
@@ -354,7 +354,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@Override
public void setWritable(@NotNull final VirtualFile file, final boolean writableFlag) throws IOException {
public void setWritable(@NotNull VirtualFile file, boolean writableFlag) throws IOException {
getDelegate(file).setWritable(file, writableFlag);
boolean oldWritable = isWritable(file);
if (oldWritable != writableFlag) {
@@ -370,7 +370,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
if (children.length > 0) {
// fast path, check that some child has same nameId as given name, this avoid O(N) on retrieving names for processing non-cached children
int nameId = FSRecords.getNameId(childName);
for (final int childId : children) {
for (int childId : children) {
if (nameId == FSRecords.getNameId(childId)) {
return childId;
}
@@ -378,7 +378,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
// for case sensitive system the above check is exhaustive in consistent state of vfs
}
for (final int childId : children) {
for (int childId : children) {
if (namesEqual(fs, childName, FSRecords.getNameSequence(childId))) return childId;
}
@@ -453,7 +453,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@Override
public void deleteFile(final Object requestor, @NotNull final VirtualFile file) throws IOException {
public void deleteFile(Object requestor, @NotNull VirtualFile file) throws IOException {
final NewVirtualFileSystem delegate = getDelegate(file);
delegate.deleteFile(requestor, file);
@@ -463,7 +463,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@Override
public void renameFile(final Object requestor, @NotNull VirtualFile file, @NotNull String newName) throws IOException {
public void renameFile(Object requestor, @NotNull VirtualFile file, @NotNull String newName) throws IOException {
getDelegate(file).renameFile(requestor, file, newName);
String oldName = file.getName();
if (!newName.equals(oldName)) {
@@ -473,13 +473,13 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
@Override
@NotNull
public byte[] contentsToByteArray(@NotNull final VirtualFile file) throws IOException {
public byte[] contentsToByteArray(@NotNull VirtualFile file) throws IOException {
return contentsToByteArray(file, true);
}
@Override
@NotNull
public byte[] contentsToByteArray(@NotNull final VirtualFile file, boolean cacheContent) throws IOException {
public byte[] contentsToByteArray(@NotNull VirtualFile file, boolean cacheContent) throws IOException {
InputStream contentStream = null;
boolean reloadFromDelegate;
boolean outdated;
@@ -543,7 +543,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
@Override
@NotNull
public InputStream getInputStream(@NotNull final VirtualFile file) throws IOException {
public InputStream getInputStream(@NotNull VirtualFile file) throws IOException {
synchronized (myInputLock) {
InputStream contentStream;
if (mustReloadContent(file) || FileUtilRt.isTooLarge(file.getLength()) || (contentStream = readContent(file)) == null) {
@@ -564,10 +564,11 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
return len;
}
private InputStream createReplicator(@NotNull final VirtualFile file,
final InputStream nativeStream,
final long fileLength,
final boolean readOnly) {
@NotNull
private InputStream createReplicator(@NotNull VirtualFile file,
@NotNull InputStream nativeStream,
long fileLength,
boolean readOnly) {
if (nativeStream instanceof BufferExposingByteArrayInputStream) {
// optimization
BufferExposingByteArrayInputStream byteStream = (BufferExposingByteArrayInputStream )nativeStream;
@@ -606,10 +607,10 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
@Override
@NotNull
public OutputStream getOutputStream(@NotNull final VirtualFile file,
final Object requestor,
final long modStamp,
final long timeStamp) {
public OutputStream getOutputStream(@NotNull VirtualFile file,
Object requestor,
long modStamp,
long timeStamp) {
return new ByteArrayOutputStream() {
private boolean closed; // protection against user calling .close() twice
@@ -664,7 +665,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
@Override
public void moveFile(final Object requestor, @NotNull final VirtualFile file, @NotNull final VirtualFile newParent) throws IOException {
public void moveFile(Object requestor, @NotNull VirtualFile file, @NotNull VirtualFile newParent) throws IOException {
getDelegate(file).moveFile(requestor, file, newParent);
processEvent(new VFileMoveEvent(requestor, file, newParent));
}
@@ -1054,13 +1055,13 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
@Override
@Nullable
public NewVirtualFile findFileById(final int id) {
public NewVirtualFile findFileById(int id) {
VirtualFileSystemEntry cached = myIdToDirCache.get(id);
return cached != null ? cached : FSRecords.findFileById(id, myIdToDirCache);
}
@Override
public NewVirtualFile findFileByIdIfCached(final int id) {
public NewVirtualFile findFileByIdIfCached(int id) {
return myVfsData.hasLoadedFile(id) ? findFileById(id) : null;
}
@@ -1073,7 +1074,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
@Override
@NotNull
public VirtualFile[] getRoots(@NotNull final NewVirtualFileSystem fs) {
public VirtualFile[] getRoots(@NotNull NewVirtualFileSystem fs) {
final List<VirtualFile> roots = new ArrayList<>();
for (NewVirtualFile root : myRoots.values()) {
@@ -1116,14 +1117,14 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
VirtualFile file = contentUpdateEvent.getFile();
long length = contentUpdateEvent.getNewLength();
long timestamp = contentUpdateEvent.getNewTimestamp();
if (!contentUpdateEvent.isLengthAndTimestampDiffProvided()) {
final NewVirtualFileSystem delegate = getDelegate(file);
final FileAttributes attributes = delegate.getAttributes(file);
length = attributes != null ? attributes.length : DEFAULT_LENGTH;
timestamp = attributes != null ? attributes.lastModified : DEFAULT_TIMESTAMP;
}
executeTouch(file, contentUpdateEvent.isFromRefresh(), contentUpdateEvent.getModificationStamp(), length, timestamp);
}
else if (event instanceof VFileCopyEvent) {
@@ -1196,7 +1197,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
return childId;
}
private static void appendIdToParentList(final int parentId, final int childId) {
private static void appendIdToParentList(int parentId, int childId) {
int[] childrenList = FSRecords.list(parentId);
childrenList = ArrayUtil.append(childrenList, childId);
FSRecords.updateList(parentId, childrenList);
@@ -1243,7 +1244,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
}
}
private static void removeIdFromParentList(final int parentId, final int id, @NotNull VirtualFile parent, VirtualFile file) {
private static void removeIdFromParentList(int parentId, int id, @NotNull VirtualFile parent, VirtualFile file) {
int[] childList = FSRecords.list(parentId);
int index = ArrayUtil.indexOf(childList, id);
@@ -1256,7 +1257,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
FSRecords.updateList(parentId, childList);
}
private static void executeRename(@NotNull VirtualFile file, @NotNull final String newName) {
private static void executeRename(@NotNull VirtualFile file, @NotNull String newName) {
final int id = getFileId(file);
FSRecords.setName(id, newName);
((VirtualFileSystemEntry)file).setNewName(newName);
@@ -1280,7 +1281,7 @@ public class PersistentFSImpl extends PersistentFS implements BaseComponent, Dis
setFlag(getFileId(file), mask, value);
}
private static void setFlag(final int id, final int mask, final boolean value) {
private static void setFlag(int id, int mask, boolean value) {
int oldFlags = FSRecords.getFlags(id);
int flags = value ? oldFlags | mask : oldFlags & ~mask;
@@ -30,7 +30,7 @@ public class ReplicatorInputStream extends InputStream {
private final InputStream mySource;
private int markedSize;
public ReplicatorInputStream(final InputStream source, final BufferExposingByteArrayOutputStream target) {
public ReplicatorInputStream(@NotNull InputStream source, @NotNull BufferExposingByteArrayOutputStream target) {
mySource = source;
myTarget = target;
}
@@ -15,6 +15,9 @@
*/
package com.intellij.util.io;
import com.intellij.openapi.util.io.ByteArraySequence;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
@@ -37,30 +40,35 @@ public class UnsyncByteArrayOutputStream extends OutputStream {
@Override
public void write(int b) {
int newcount = myCount + 1;
if (newcount > myBuffer.length || myIsShared) {
myBuffer = Arrays.copyOf(myBuffer, newcount > myBuffer.length ? Math.max(myBuffer.length << 1, newcount):myBuffer.length);
int newCount = myCount + 1;
if (newCount > myBuffer.length || myIsShared) {
grow(newCount);
myIsShared = false;
}
myBuffer[myCount] = (byte)b;
myCount = newcount;
myCount = newCount;
}
private void grow(int newCount) {
myBuffer = Arrays.copyOf(myBuffer, newCount > myBuffer.length ? Math.max(myBuffer.length << 1, newCount) : myBuffer.length);
}
@Override
public void write(byte[] b, int off, int len) {
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
public void write(@NotNull byte[] b, int off, int len) {
if (off < 0 || off > b.length || len < 0 ||
off + len > b.length || off + len < 0) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
}
if (len == 0) {
return;
}
int newcount = myCount + len;
if (newcount > myBuffer.length || myIsShared) {
myBuffer = Arrays.copyOf(myBuffer, newcount > myBuffer.length ? Math.max(myBuffer.length << 1, newcount): myBuffer.length);
int newCount = myCount + len;
if (newCount > myBuffer.length || myIsShared) {
grow(newCount);
myIsShared = false;
}
System.arraycopy(b, off, myBuffer, myCount, len);
myCount = newcount;
myCount = newCount;
}
public void writeTo(OutputStream out) throws IOException {
@@ -83,7 +91,13 @@ public class UnsyncByteArrayOutputStream extends OutputStream {
return myCount;
}
@Override
public String toString() {
return new String(myBuffer, 0, myCount);
}
@NotNull
public ByteArraySequence toByteArraySequence() {
return new ByteArraySequence(myBuffer, 0, myCount);
}
}