Skip to content

Commit

Permalink
[#2844] Add encoding to the IResourcesSetupUtil.createTempFile method.
Browse files Browse the repository at this point in the history
- Extend the IResourcesSetupUtil class by a createTempFile method that
accepts a charset as a parameter to be able to configure the encoding.

Signed-off-by: miklossy <[email protected]>
  • Loading branch information
miklossy committed Jul 11, 2024
1 parent f17d252 commit fc68030
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2019 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2009, 2024 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand All @@ -13,6 +13,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
import java.nio.file.Files;

import org.eclipse.core.resources.ICommand;
Expand Down Expand Up @@ -251,8 +252,16 @@ protected void execute(IProgressMonitor monitor)

public static File createTempFile(String fileName, String suffix, String content)
throws Exception {
return createTempFile(fileName, suffix, content, Charset.defaultCharset());
}

/**
* since 2.36
*/
public static File createTempFile(String fileName, String suffix, String content, Charset charset)
throws Exception {
File file = Files.createTempFile(fileName, suffix).toFile();
try (FileWriter writer = new FileWriter(file)) {
try (FileWriter writer = new FileWriter(file, charset)) {
writer.write(content);
}
return file;
Expand Down

0 comments on commit fc68030

Please sign in to comment.