mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
[images] IJPL-149620 ImageInfoIndex clinit requests GistManager instance
GitOrigin-RevId: 956f061f2ff35aec61a787bcfc39dd7366470848
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4e26888d95
commit
1016fab2ac
@@ -1,6 +1,8 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.intellij.images.index;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.Service;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -21,15 +23,11 @@ import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
@Service
|
||||
public final class ImageInfoIndex {
|
||||
@Nullable
|
||||
public static ImageInfo getInfo(@NotNull VirtualFile file, @NotNull Project project) {
|
||||
return ourGist.getFileData(project, file);
|
||||
}
|
||||
private final long myMaxImageSize = (long)(Registry.get("ide.index.image.max.size").asDouble() * 1024 * 1024);
|
||||
|
||||
private static final long ourMaxImageSize = (long)(Registry.get("ide.index.image.max.size").asDouble() * 1024 * 1024);
|
||||
|
||||
private static final DataExternalizer<ImageInfo> ourValueExternalizer = new DataExternalizer<>() {
|
||||
private final DataExternalizer<ImageInfo> myValueExternalizer = new DataExternalizer<>() {
|
||||
@Override
|
||||
public void save(@NotNull final DataOutput out, final ImageInfo info) throws IOException {
|
||||
DataInputOutputUtil.writeINT(out, info.width);
|
||||
@@ -45,9 +43,9 @@ public final class ImageInfoIndex {
|
||||
}
|
||||
};
|
||||
|
||||
private static final VirtualFileGist<ImageInfo> ourGist =
|
||||
GistManager.getInstance().newVirtualFileGist("ImageInfo", 1, ourValueExternalizer, (project, file) -> {
|
||||
if (!file.isInLocalFileSystem() || file.getLength() > ourMaxImageSize) {
|
||||
private final VirtualFileGist<ImageInfo> myGist =
|
||||
GistManager.getInstance().newVirtualFileGist("ImageInfo", 1, myValueExternalizer, (project, file) -> {
|
||||
if (!file.isInLocalFileSystem() || file.getLength() > myMaxImageSize) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -67,4 +65,16 @@ public final class ImageInfoIndex {
|
||||
ImageInfoReader.Info info = ImageInfoReader.getInfo(content);
|
||||
return info == null ? null : new ImageInfo(info.width, info.height, info.bpp);
|
||||
});
|
||||
|
||||
public @Nullable ImageInfo get(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
return myGist.getFileData(project, file);
|
||||
}
|
||||
|
||||
public static ImageInfoIndex getInstance() {
|
||||
return ApplicationManager.getApplication().getService(ImageInfoIndex.class);
|
||||
}
|
||||
|
||||
public static @Nullable ImageInfo getInfo(@NotNull VirtualFile file, @NotNull Project project) {
|
||||
return getInstance().get(project, file);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user