mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify StreamProvider.saveContent — we don't user returned value in any case
This commit is contained in:
+1
-2
@@ -32,9 +32,8 @@ final class OldStreamProviderAdapter extends StreamProvider implements CurrentUs
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException {
|
||||
public void saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException {
|
||||
myProvider.saveContent(fileSpec, new BufferExposingByteArrayInputStream(content, size), size, roamingType, async);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+3
-8
@@ -575,22 +575,17 @@ public abstract class StateStorageManagerImpl implements StateStorageManager, Di
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException {
|
||||
boolean result = false;
|
||||
public void saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException {
|
||||
for (StreamProvider streamProvider : myStreamProviders) {
|
||||
try {
|
||||
if (streamProvider.isEnabled() && streamProvider.isApplicable(fileSpec, roamingType) && streamProvider.saveContent(fileSpec, content, size, roamingType, async)) {
|
||||
result = true;
|
||||
if (streamProvider.isEnabled() && streamProvider.isApplicable(fileSpec, roamingType)) {
|
||||
streamProvider.saveContent(fileSpec, content, size, roamingType, async);
|
||||
}
|
||||
}
|
||||
catch (ConnectException e) {
|
||||
LOG.debug("Cannot send user profile to server: " + e.getLocalizedMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.debug(e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-6
@@ -274,17 +274,16 @@ public class StorageUtil {
|
||||
return writeToBytes(document, useSystemLineSeparator ? SystemProperties.getLineSeparator() : "\n");
|
||||
}
|
||||
|
||||
public static boolean sendContent(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull Document copy, @NotNull RoamingType type, boolean async) {
|
||||
public static void sendContent(@NotNull StreamProvider provider, @NotNull String fileSpec, @NotNull Document copy, @NotNull RoamingType type, boolean async) {
|
||||
if (!provider.isApplicable(fileSpec, type)) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
return doSendContent(provider, fileSpec, copy, type, async);
|
||||
doSendContent(provider, fileSpec, copy, type, async);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,10 +296,10 @@ public class StorageUtil {
|
||||
/**
|
||||
* You must call {@link StreamProvider#isApplicable(String, com.intellij.openapi.components.RoamingType)} before
|
||||
*/
|
||||
public static boolean doSendContent(StreamProvider provider, String fileSpec, Document copy, RoamingType type, boolean async) throws IOException {
|
||||
public static void doSendContent(StreamProvider provider, String fileSpec, Document copy, RoamingType type, boolean async) throws IOException {
|
||||
// we should use standard line-separator (\n) - stream provider can share file content on any OS
|
||||
BufferExposingByteArrayOutputStream content = documentToBytes(copy, false);
|
||||
return provider.saveContent(fileSpec, content.getInternalBuffer(), content.size(), type, async);
|
||||
provider.saveContent(fileSpec, content.getInternalBuffer(), content.size(), type, async);
|
||||
}
|
||||
|
||||
public static void logStateDiffInfo(Set<Pair<VirtualFile, StateStorage>> changedFiles, Set<String> componentNames) {
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public abstract class StreamProvider {
|
||||
* @param roamingType
|
||||
* @param async
|
||||
*/
|
||||
public abstract boolean saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException;
|
||||
public abstract void saveContent(@NotNull String fileSpec, @NotNull byte[] content, int size, @NotNull RoamingType roamingType, boolean async) throws IOException;
|
||||
|
||||
@Nullable
|
||||
public abstract InputStream loadContent(@NotNull String fileSpec, @NotNull RoamingType roamingType) throws IOException;
|
||||
|
||||
+14
-18
@@ -382,11 +382,7 @@ public abstract class XmlElementStorage implements StateStorage, Disposable {
|
||||
try {
|
||||
if (myStreamProvider != null && myStreamProvider.isEnabled() && (myProviderUpToDateHash == -1 || myProviderUpToDateHash != hash)) {
|
||||
try {
|
||||
//noinspection IfStatementWithIdenticalBranches
|
||||
if (saveForProvider(myStreamProvider)) {
|
||||
//noinspection UnnecessaryReturnStatement
|
||||
return;
|
||||
}
|
||||
saveForProvider(myStreamProvider);
|
||||
}
|
||||
finally {
|
||||
myProviderUpToDateHash = hash;
|
||||
@@ -409,15 +405,15 @@ public abstract class XmlElementStorage implements StateStorage, Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean saveForProvider(@NotNull StreamProvider streamProvider) {
|
||||
private void saveForProvider(@NotNull StreamProvider streamProvider) {
|
||||
if (!streamProvider.isApplicable(myFileSpec, RoamingType.PER_USER)) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
Document document = getDocumentToSave();
|
||||
Element rootElement = document.getRootElement();
|
||||
if (rootElement.getChildren().isEmpty()) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
// skip the whole document if some component has disabled roaming type
|
||||
@@ -427,27 +423,29 @@ public abstract class XmlElementStorage implements StateStorage, Disposable {
|
||||
// but this project id must not be shared
|
||||
if (!myFileSpec.equals(StoragePathMacros.WORKSPACE_FILE) &&
|
||||
rootElement.getContent(new RoamingElementFilter(RoamingType.DISABLED)).iterator().hasNext()) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
RoamingElementFilter perPlatformFilter = new RoamingElementFilter(RoamingType.PER_PLATFORM);
|
||||
if (rootElement.getContent(perPlatformFilter).iterator().hasNext()) {
|
||||
return doSaveForProvider(rootElement, new RoamingElementFilter(RoamingType.PER_USER)) ||
|
||||
doSaveForProvider(rootElement, perPlatformFilter);
|
||||
doSaveForProvider(rootElement, new RoamingElementFilter(RoamingType.PER_USER));
|
||||
doSaveForProvider(rootElement, perPlatformFilter);
|
||||
}
|
||||
else {
|
||||
return doSaveForProvider(document, RoamingType.PER_USER, streamProvider);
|
||||
doSaveForProvider(document, RoamingType.PER_USER, streamProvider);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doSaveForProvider(Element element, RoamingElementFilter filter) {
|
||||
private void doSaveForProvider(Element element, RoamingElementFilter filter) {
|
||||
Element copiedElement = JDOMUtil.cloneElement(element, filter);
|
||||
return copiedElement != null && doSaveForProvider(new Document(copiedElement), filter.myRoamingType, myStreamProvider);
|
||||
if (copiedElement != null) {
|
||||
doSaveForProvider(new Document(copiedElement), filter.myRoamingType, myStreamProvider);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean doSaveForProvider(Document actualDocument, RoamingType roamingType, StreamProvider streamProvider) {
|
||||
private void doSaveForProvider(Document actualDocument, RoamingType roamingType, StreamProvider streamProvider) {
|
||||
try {
|
||||
boolean result = StorageUtil.doSendContent(streamProvider, myFileSpec, actualDocument, roamingType, true);
|
||||
StorageUtil.doSendContent(streamProvider, myFileSpec, actualDocument, roamingType, true);
|
||||
if (streamProvider.isVersioningRequired()) {
|
||||
TObjectLongHashMap<String> versions = loadVersions(actualDocument.getRootElement().getChildren(StorageData.COMPONENT));
|
||||
if (!versions.isEmpty()) {
|
||||
@@ -455,11 +453,9 @@ public abstract class XmlElementStorage implements StateStorage, Disposable {
|
||||
StorageUtil.doSendContent(streamProvider, myFileSpec + VERSION_FILE_SUFFIX, versionDoc, roamingType, true);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user