IDEA-78117 NULL characters appended to file when retrieving historical revisions in SVN

This commit is contained in:
irengrig
2012-07-20 19:43:42 +04:00
parent be89d60142
commit 0f6ece995e
2 changed files with 10 additions and 5 deletions
@@ -30,13 +30,13 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.wc.SVNInfo;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
/**
* @author yole
@@ -118,19 +118,21 @@ public class SvnContentRevision implements ContentRevision, MarkerVcsContentRevi
buffer.close();
}
catch (SVNException e) {
try {
/*try {
final SVNInfo info = wcClient.doInfo(file, SVNRevision.UNDEFINED);
//todo
}
catch (SVNException e1) {
throw new VcsException(e);
}
}*/
throw new VcsException(e);
}
catch (IOException e) {
throw new VcsException(e);
}
return buffer.toByteArray();
final byte[] bytes = buffer.toByteArray();
final Charset charset = myFile.getCharset();
return charset == null ? bytes : SvnUtil.decode(charset, bytes);
}
@NotNull
@@ -48,6 +48,7 @@ import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.*;
@@ -683,7 +684,9 @@ public class SvnUtil {
public static byte[] decode(final Charset charset, final byte[] buffer) {
if (charset != null && ! CharsetToolkit.UTF8_CHARSET.equals(charset)) {
return CharsetToolkit.UTF8_CHARSET.encode(charset.decode(ByteBuffer.wrap(buffer))).array();
final CharBuffer decoded = charset.decode(ByteBuffer.wrap(buffer));
final ByteBuffer byteBuffer = CharsetToolkit.UTF8_CHARSET.encode(decoded);
return ArrayUtil.realloc(byteBuffer.array(), byteBuffer.remaining());
}
return buffer;
}