Specify charset when constructing PrintWriter
Change-Id: I79170cbcbc573b037542a439592ca8de063fbd47
This commit is contained in:
@@ -15,11 +15,13 @@
|
|||||||
package com.google.gerrit.server.index;
|
package com.google.gerrit.server.index;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.common.base.Stopwatch;
|
import com.google.common.base.Stopwatch;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -64,7 +66,7 @@ public abstract class SiteIndexer<K, V, I extends Index<K, V>> {
|
|||||||
|
|
||||||
protected int totalWork = -1;
|
protected int totalWork = -1;
|
||||||
protected OutputStream progressOut = NullOutputStream.INSTANCE;
|
protected OutputStream progressOut = NullOutputStream.INSTANCE;
|
||||||
protected PrintWriter verboseWriter = new PrintWriter(NullOutputStream.INSTANCE);
|
protected PrintWriter verboseWriter = newPrintWriter(NullOutputStream.INSTANCE);
|
||||||
|
|
||||||
public void setTotalWork(int num) {
|
public void setTotalWork(int num) {
|
||||||
totalWork = num;
|
totalWork = num;
|
||||||
@@ -75,7 +77,7 @@ public abstract class SiteIndexer<K, V, I extends Index<K, V>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setVerboseOut(OutputStream out) {
|
public void setVerboseOut(OutputStream out) {
|
||||||
verboseWriter = new PrintWriter(checkNotNull(out));
|
verboseWriter = newPrintWriter(checkNotNull(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Result indexAll(I index);
|
public abstract Result indexAll(I index);
|
||||||
@@ -86,6 +88,10 @@ public abstract class SiteIndexer<K, V, I extends Index<K, V>> {
|
|||||||
new ErrorListener(future, desc, progress, ok), MoreExecutors.directExecutor());
|
new ErrorListener(future, desc, progress, ok), MoreExecutors.directExecutor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected PrintWriter newPrintWriter(OutputStream out) {
|
||||||
|
return new PrintWriter(new OutputStreamWriter(out, UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
private static class ErrorListener implements Runnable {
|
private static class ErrorListener implements Runnable {
|
||||||
private final ListenableFuture<?> future;
|
private final ListenableFuture<?> future;
|
||||||
private final String desc;
|
private final String desc;
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import com.google.gwtorm.server.OrmException;
|
|||||||
import com.google.gwtorm.server.SchemaFactory;
|
import com.google.gwtorm.server.SchemaFactory;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@@ -62,7 +61,7 @@ public class AllAccountsIndexer extends SiteIndexer<Account.Id, AccountState, Ac
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SiteIndexer.Result indexAll(final AccountIndex index) {
|
public SiteIndexer.Result indexAll(final AccountIndex index) {
|
||||||
ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
|
ProgressMonitor progress = new TextProgressMonitor(newPrintWriter(progressOut));
|
||||||
progress.start(2);
|
progress.start(2);
|
||||||
Stopwatch sw = Stopwatch.createStarted();
|
Stopwatch sw = Stopwatch.createStarted();
|
||||||
List<Account.Id> ids;
|
List<Account.Id> ids;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import com.google.gwtorm.server.OrmException;
|
|||||||
import com.google.gwtorm.server.SchemaFactory;
|
import com.google.gwtorm.server.SchemaFactory;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@@ -61,7 +60,7 @@ public class AllGroupsIndexer extends SiteIndexer<AccountGroup.UUID, AccountGrou
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SiteIndexer.Result indexAll(GroupIndex index) {
|
public SiteIndexer.Result indexAll(GroupIndex index) {
|
||||||
ProgressMonitor progress = new TextProgressMonitor(new PrintWriter(progressOut));
|
ProgressMonitor progress = new TextProgressMonitor(newPrintWriter(progressOut));
|
||||||
progress.start(2);
|
progress.start(2);
|
||||||
Stopwatch sw = Stopwatch.createStarted();
|
Stopwatch sw = Stopwatch.createStarted();
|
||||||
List<AccountGroup.UUID> uuids;
|
List<AccountGroup.UUID> uuids;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import com.google.common.collect.ListMultimap;
|
|||||||
import com.google.common.net.HttpHeaders;
|
import com.google.common.net.HttpHeaders;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -106,7 +107,7 @@ public class FakeHttpServletResponse implements HttpServletResponse {
|
|||||||
public synchronized PrintWriter getWriter() {
|
public synchronized PrintWriter getWriter() {
|
||||||
checkState(outputStream == null, "getOutputStream() already called");
|
checkState(outputStream == null, "getOutputStream() already called");
|
||||||
if (writer == null) {
|
if (writer == null) {
|
||||||
writer = new PrintWriter(actualBody);
|
writer = new PrintWriter(new OutputStreamWriter(actualBody, UTF_8));
|
||||||
}
|
}
|
||||||
return writer;
|
return writer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user