fix #2231 replace createTempFile
This commit is contained in:
parent
d7c2ebca5f
commit
21cf96fcc4
20 changed files with 51 additions and 45 deletions
|
@ -70,7 +70,6 @@ import org.lastaflute.web.response.ActionResponse;
|
|||
import org.lastaflute.web.response.HtmlResponse;
|
||||
import org.lastaflute.web.response.StreamResponse;
|
||||
import org.lastaflute.web.ruts.process.ActionRuntime;
|
||||
import org.lastaflute.web.validation.exception.ValidationErrorException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xml.sax.InputSource;
|
||||
|
@ -118,17 +117,18 @@ public class AdminBackupAction extends FessAdminAction {
|
|||
validate(form, messages -> {}, () -> asListHtml());
|
||||
verifyToken(() -> asListHtml());
|
||||
final String fileName = form.bulkFile.getFileName();
|
||||
File tempFile = null;
|
||||
try {
|
||||
tempFile = File.createTempFile("fess_restore_", ".tmp");
|
||||
try (final InputStream in = form.bulkFile.getInputStream(); final OutputStream out = new FileOutputStream(tempFile)) {
|
||||
CopyUtil.copy(in, out);
|
||||
}
|
||||
File tempFile = ComponentUtil.getSystemHelper().createTempFile("fess_restore_", ".tmp");
|
||||
try (final InputStream in = form.bulkFile.getInputStream(); final OutputStream out = new FileOutputStream(tempFile)) {
|
||||
CopyUtil.copy(in, out);
|
||||
asyncImport(fileName, tempFile);
|
||||
} catch (final ValidationErrorException e) {
|
||||
throw e;
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to import " + fileName, e);
|
||||
} catch (final IOException e) {
|
||||
logger.warn("Failed to create a temp file.", e);
|
||||
if (tempFile.exists() && !tempFile.delete()) {
|
||||
logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
|
||||
}
|
||||
throwValidationError(messages -> messages.addErrorsFileIsNotSupported(GLOBAL, fileName), () -> {
|
||||
return asListHtml();
|
||||
});
|
||||
}
|
||||
saveInfo(messages -> messages.addSuccessBulkProcessStarted(GLOBAL));
|
||||
return redirect(getClass()); // no-op
|
||||
|
|
|
@ -187,7 +187,7 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
verifyToken(() -> asDownloadHtml());
|
||||
|
||||
return asStream("badword.csv").contentTypeOctetStream().stream(out -> {
|
||||
final Path tempFile = Files.createTempFile(null, null);
|
||||
final Path tempFile = ComponentUtil.getSystemHelper().createTempFile("fess-badword-", ".csv").toPath();
|
||||
try {
|
||||
try (Writer writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(tempFile), getCsvEncoding()))) {
|
||||
badWordService.exportCsv(writer);
|
||||
|
|
|
@ -219,7 +219,7 @@ public class AdminElevatewordAction extends FessAdminAction {
|
|||
verifyToken(() -> asDownloadHtml());
|
||||
|
||||
return asStream("elevate.csv").contentTypeOctetStream().stream(out -> {
|
||||
final Path tempFile = Files.createTempFile(null, null);
|
||||
final Path tempFile = ComponentUtil.getSystemHelper().createTempFile("fess-elevate-", ".csv").toPath();
|
||||
try {
|
||||
try (Writer writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(tempFile), getCsvEncoding()))) {
|
||||
elevateWordService.exportCsv(writer);
|
||||
|
|
|
@ -83,7 +83,7 @@ public class AdminEsreqAction extends FessAdminAction {
|
|||
});
|
||||
} else {
|
||||
try (final CurlResponse response = curlRequest.body(buf.toString()).execute()) {
|
||||
final File tempFile = File.createTempFile("esreq_", ".json");
|
||||
final File tempFile = ComponentUtil.getSystemHelper().createTempFile("esreq_", ".json");
|
||||
try (final InputStream in = response.getContentAsStream()) {
|
||||
CopyUtil.copy(in, tempFile);
|
||||
} catch (final Exception e1) {
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.codelibs.fess.app.web.api.admin.FessApiAdminAction;
|
|||
import org.codelibs.fess.es.config.exentity.BadWord;
|
||||
import org.codelibs.fess.exception.FessSystemException;
|
||||
import org.codelibs.fess.helper.SuggestHelper;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.response.JsonResponse;
|
||||
import org.lastaflute.web.response.StreamResponse;
|
||||
|
@ -162,7 +163,7 @@ public class ApiAdminBadwordAction extends FessApiAdminAction {
|
|||
public StreamResponse get$download(final DownloadBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
return asStream("badword.csv").contentTypeOctetStream().stream(out -> {
|
||||
final Path tempFile = Files.createTempFile(null, null);
|
||||
final Path tempFile = ComponentUtil.getSystemHelper().createTempFile("fess-badword-", ".csv").toPath();
|
||||
try {
|
||||
try (Writer writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(tempFile), getCsvEncoding()))) {
|
||||
badWordService.exportCsv(writer);
|
||||
|
|
|
@ -174,7 +174,7 @@ public class ApiAdminElevatewordAction extends FessApiAdminAction {
|
|||
public StreamResponse get$download(final DownloadBody body) {
|
||||
validateApi(body, messages -> {});
|
||||
return asStream("elevate.csv").contentTypeOctetStream().stream(out -> {
|
||||
final Path tempFile = Files.createTempFile(null, null);
|
||||
final Path tempFile = ComponentUtil.getSystemHelper().createTempFile("fess-elevate-", ".csv").toPath();
|
||||
try {
|
||||
try (Writer writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(tempFile), getCsvEncoding()))) {
|
||||
elevateWordService.exportCsv(writer);
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.codelibs.curl.CurlResponse;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.dict.DictionaryException;
|
||||
import org.codelibs.fess.dict.DictionaryFile;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.KuromojiCSVUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
|
||||
|
@ -208,9 +209,9 @@ public class KuromojiFile extends DictionaryFile<KuromojiItem> {
|
|||
|
||||
protected KuromojiUpdater(final KuromojiItem newItem) {
|
||||
try {
|
||||
newFile = File.createTempFile(KUROMOJI, ".txt");
|
||||
newFile = ComponentUtil.getSystemHelper().createTempFile(KUROMOJI, ".txt");
|
||||
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), Constants.UTF_8));
|
||||
} catch (final IOException e) {
|
||||
} catch (final Exception e) {
|
||||
if (newFile != null) {
|
||||
newFile.delete();
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.codelibs.curl.CurlResponse;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.dict.DictionaryException;
|
||||
import org.codelibs.fess.dict.DictionaryFile;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -222,9 +223,9 @@ public class CharMappingFile extends DictionaryFile<CharMappingItem> {
|
|||
|
||||
protected MappingUpdater(final CharMappingItem newItem) {
|
||||
try {
|
||||
newFile = File.createTempFile(MAPPING, ".txt");
|
||||
newFile = ComponentUtil.getSystemHelper().createTempFile(MAPPING, ".txt");
|
||||
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), Constants.UTF_8));
|
||||
} catch (final IOException e) {
|
||||
} catch (final Exception e) {
|
||||
if (newFile != null) {
|
||||
newFile.delete();
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.codelibs.curl.CurlResponse;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.dict.DictionaryException;
|
||||
import org.codelibs.fess.dict.DictionaryFile;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
|
||||
public class ProtwordsFile extends DictionaryFile<ProtwordsItem> {
|
||||
|
@ -206,9 +207,9 @@ public class ProtwordsFile extends DictionaryFile<ProtwordsItem> {
|
|||
|
||||
protected ProtwordsUpdater(final ProtwordsItem newItem) {
|
||||
try {
|
||||
newFile = File.createTempFile(PROTWORDS, ".txt");
|
||||
newFile = ComponentUtil.getSystemHelper().createTempFile(PROTWORDS, ".txt");
|
||||
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), Constants.UTF_8));
|
||||
} catch (final IOException e) {
|
||||
} catch (final Exception e) {
|
||||
if (newFile != null) {
|
||||
newFile.delete();
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.codelibs.curl.CurlResponse;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.dict.DictionaryException;
|
||||
import org.codelibs.fess.dict.DictionaryFile;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -219,9 +220,9 @@ public class StemmerOverrideFile extends DictionaryFile<StemmerOverrideItem> {
|
|||
|
||||
protected StemmerOverrideUpdater(final StemmerOverrideItem newItem) {
|
||||
try {
|
||||
newFile = File.createTempFile(STEMMER_OVERRIDE, ".txt");
|
||||
newFile = ComponentUtil.getSystemHelper().createTempFile(STEMMER_OVERRIDE, ".txt");
|
||||
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), Constants.UTF_8));
|
||||
} catch (final IOException e) {
|
||||
} catch (final Exception e) {
|
||||
if (newFile != null) {
|
||||
newFile.delete();
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.codelibs.curl.CurlResponse;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.dict.DictionaryException;
|
||||
import org.codelibs.fess.dict.DictionaryFile;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
|
||||
public class StopwordsFile extends DictionaryFile<StopwordsItem> {
|
||||
|
@ -206,9 +207,9 @@ public class StopwordsFile extends DictionaryFile<StopwordsItem> {
|
|||
|
||||
protected SynonymUpdater(final StopwordsItem newItem) {
|
||||
try {
|
||||
newFile = File.createTempFile(STOPWORDS, ".txt");
|
||||
newFile = ComponentUtil.getSystemHelper().createTempFile(STOPWORDS, ".txt");
|
||||
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), Constants.UTF_8));
|
||||
} catch (final IOException e) {
|
||||
} catch (final Exception e) {
|
||||
if (newFile != null) {
|
||||
newFile.delete();
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.codelibs.curl.CurlResponse;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.dict.DictionaryException;
|
||||
import org.codelibs.fess.dict.DictionaryFile;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.dbflute.optional.OptionalEntity;
|
||||
|
||||
public class SynonymFile extends DictionaryFile<SynonymItem> {
|
||||
|
@ -280,9 +281,9 @@ public class SynonymFile extends DictionaryFile<SynonymItem> {
|
|||
|
||||
protected SynonymUpdater(final SynonymItem newItem) {
|
||||
try {
|
||||
newFile = File.createTempFile(SYNONYM, ".txt");
|
||||
newFile = ComponentUtil.getSystemHelper().createTempFile(SYNONYM, ".txt");
|
||||
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), Constants.UTF_8));
|
||||
} catch (final IOException e) {
|
||||
} catch (final Exception e) {
|
||||
if (newFile != null) {
|
||||
newFile.delete();
|
||||
}
|
||||
|
|
|
@ -313,13 +313,13 @@ public class Crawler {
|
|||
systemProperties.reload(options.propertiesPath);
|
||||
} else {
|
||||
try {
|
||||
final File propFile = File.createTempFile("crawler_", ".properties");
|
||||
final File propFile = ComponentUtil.getSystemHelper().createTempFile("crawler_", ".properties");
|
||||
if (propFile.delete() && logger.isDebugEnabled()) {
|
||||
logger.debug("Deleted a temp file: " + propFile.getAbsolutePath());
|
||||
}
|
||||
systemProperties.reload(propFile.getAbsolutePath());
|
||||
propFile.deleteOnExit();
|
||||
} catch (final IOException e) {
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to create system properties file.", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
package org.codelibs.fess.exec;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
@ -168,13 +167,13 @@ public class SuggestCreator {
|
|||
systemProperties.reload(options.propertiesPath);
|
||||
} else {
|
||||
try {
|
||||
final File propFile = File.createTempFile("suggest_", ".properties");
|
||||
final File propFile = ComponentUtil.getSystemHelper().createTempFile("suggest_", ".properties");
|
||||
if (propFile.delete() && logger.isDebugEnabled()) {
|
||||
logger.debug("Deleted a temp file: " + propFile.getAbsolutePath());
|
||||
}
|
||||
systemProperties.reload(propFile.getAbsolutePath());
|
||||
propFile.deleteOnExit();
|
||||
} catch (final IOException e) {
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to create system properties file.", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
package org.codelibs.fess.exec;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -180,13 +179,13 @@ public class ThumbnailGenerator {
|
|||
systemProperties.reload(options.propertiesPath);
|
||||
} else {
|
||||
try {
|
||||
final File propFile = File.createTempFile("thumbnail_", ".properties");
|
||||
final File propFile = ComponentUtil.getSystemHelper().createTempFile("thumbnail_", ".properties");
|
||||
if (propFile.delete() && logger.isDebugEnabled()) {
|
||||
logger.debug("Deleted a temp file: " + propFile.getAbsolutePath());
|
||||
}
|
||||
systemProperties.reload(propFile.getAbsolutePath());
|
||||
propFile.deleteOnExit();
|
||||
} catch (final IOException e) {
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to create system properties file.", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -472,7 +472,11 @@ public class SystemHelper {
|
|||
|
||||
public File createTempFile(String prefix, String suffix) {
|
||||
try {
|
||||
return File.createTempFile(prefix, suffix);
|
||||
final File file = File.createTempFile(prefix, suffix);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Create {} as a temp file.", file.getAbsolutePath());
|
||||
}
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -321,10 +321,9 @@ public class CrawlJob extends ExecJob {
|
|||
cmdList.add(Integer.toString(documentExpires));
|
||||
}
|
||||
|
||||
File propFile = null;
|
||||
File propFile = ComponentUtil.getSystemHelper().createTempFile(getExecuteType() + "_", ".properties");
|
||||
try {
|
||||
cmdList.add("-p");
|
||||
propFile = File.createTempFile(getExecuteType() + "_", ".properties");
|
||||
cmdList.add(propFile.getAbsolutePath());
|
||||
try (FileOutputStream out = new FileOutputStream(propFile)) {
|
||||
final Properties prop = new Properties();
|
||||
|
|
|
@ -202,10 +202,9 @@ public class GenerateThumbnailJob extends ExecJob {
|
|||
cmdList.add("--cleanup");
|
||||
}
|
||||
|
||||
File propFile = null;
|
||||
File propFile = ComponentUtil.getSystemHelper().createTempFile(getExecuteType() + "_", ".properties");
|
||||
try {
|
||||
cmdList.add("-p");
|
||||
propFile = File.createTempFile(getExecuteType() + "_", ".properties");
|
||||
cmdList.add(propFile.getAbsolutePath());
|
||||
try (FileOutputStream out = new FileOutputStream(propFile)) {
|
||||
final Properties prop = new Properties();
|
||||
|
|
|
@ -184,10 +184,9 @@ public class SuggestJob extends ExecJob {
|
|||
cmdList.add("--sessionId");
|
||||
cmdList.add(sessionId);
|
||||
|
||||
File propFile = null;
|
||||
File propFile = ComponentUtil.getSystemHelper().createTempFile(getExecuteType() + "_", ".properties");
|
||||
try {
|
||||
cmdList.add("-p");
|
||||
propFile = File.createTempFile(getExecuteType() + "_", ".properties");
|
||||
cmdList.add(propFile.getAbsolutePath());
|
||||
try (FileOutputStream out = new FileOutputStream(propFile)) {
|
||||
final Properties prop = new Properties();
|
||||
|
|
|
@ -30,6 +30,7 @@ import javax.annotation.PostConstruct;
|
|||
import org.codelibs.core.io.CloseableUtil;
|
||||
import org.codelibs.core.io.CopyUtil;
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -83,9 +84,8 @@ public class CommandGenerator extends BaseThumbnailGenerator {
|
|||
}
|
||||
|
||||
return process(thumbnailId, responseData -> {
|
||||
File tempFile = null;
|
||||
File tempFile = ComponentUtil.getSystemHelper().createTempFile("thumbnail_", "");
|
||||
try {
|
||||
tempFile = File.createTempFile("thumbnail_", "");
|
||||
CopyUtil.copy(responseData.getResponseBody(), tempFile);
|
||||
|
||||
final String tempPath = tempFile.getAbsolutePath();
|
||||
|
|
Loading…
Add table
Reference in a new issue