Search in sources :

Example 1 with BinaryMergeRequestImpl

use of com.intellij.diff.requests.BinaryMergeRequestImpl in project intellij-community by JetBrains.

the class DiffRequestFactoryImpl method createBinaryMergeRequest.

@NotNull
@Override
public MergeRequest createBinaryMergeRequest(@Nullable Project project, @NotNull VirtualFile output, @NotNull List<byte[]> byteContents, @Nullable String title, @NotNull List<String> contentTitles, @Nullable Consumer<MergeResult> applyCallback) throws InvalidDiffRequestException {
    if (byteContents.size() != 3)
        throw new IllegalArgumentException();
    if (contentTitles.size() != 3)
        throw new IllegalArgumentException();
    try {
        FileContent outputContent = myContentFactory.createFile(project, output);
        if (outputContent == null)
            throw new InvalidDiffRequestException("Can't process file: " + output);
        byte[] originalContent = output.contentsToByteArray();
        List<DiffContent> contents = new ArrayList<>(3);
        for (byte[] bytes : byteContents) {
            contents.add(myContentFactory.createFromBytes(project, bytes, output));
        }
        return new BinaryMergeRequestImpl(project, outputContent, originalContent, contents, byteContents, title, contentTitles, applyCallback);
    } catch (IOException e) {
        throw new InvalidDiffRequestException("Can't read from file", e);
    }
}
Also used : FileContent(com.intellij.diff.contents.FileContent) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BinaryMergeRequestImpl(com.intellij.diff.requests.BinaryMergeRequestImpl) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with BinaryMergeRequestImpl

use of com.intellij.diff.requests.BinaryMergeRequestImpl in project intellij-community by JetBrains.

the class DiffRequestFactoryImpl method createBinaryMergeRequestFromFiles.

@NotNull
public MergeRequest createBinaryMergeRequestFromFiles(@Nullable Project project, @NotNull VirtualFile output, @NotNull List<VirtualFile> fileContents, @Nullable String title, @NotNull List<String> contentTitles, @Nullable Consumer<MergeResult> applyCallback) throws InvalidDiffRequestException {
    if (fileContents.size() != 3)
        throw new IllegalArgumentException();
    if (contentTitles.size() != 3)
        throw new IllegalArgumentException();
    try {
        FileContent outputContent = myContentFactory.createFile(project, output);
        if (outputContent == null)
            throw new InvalidDiffRequestException("Can't process file: " + output.getPresentableUrl());
        byte[] originalContent = output.contentsToByteArray();
        List<DiffContent> contents = new ArrayList<>(3);
        List<byte[]> byteContents = new ArrayList<>(3);
        for (VirtualFile file : fileContents) {
            FileContent content = myContentFactory.createFile(project, file);
            if (content == null)
                throw new InvalidDiffRequestException("Can't process file: " + file.getPresentableUrl());
            contents.add(content);
            // TODO: we can read contents from file when needed
            byteContents.add(file.contentsToByteArray());
        }
        return new BinaryMergeRequestImpl(project, outputContent, originalContent, contents, byteContents, title, contentTitles, applyCallback);
    } catch (IOException e) {
        throw new InvalidDiffRequestException("Can't read from file", e);
    }
}
Also used : FileContent(com.intellij.diff.contents.FileContent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BinaryMergeRequestImpl(com.intellij.diff.requests.BinaryMergeRequestImpl) DiffContent(com.intellij.diff.contents.DiffContent) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DiffContent (com.intellij.diff.contents.DiffContent)2 FileContent (com.intellij.diff.contents.FileContent)2 BinaryMergeRequestImpl (com.intellij.diff.requests.BinaryMergeRequestImpl)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1