forked from Azure/autorest.java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Azure/autorest.java
- Loading branch information
Showing
38 changed files
with
2,341 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
extension-base/src/main/java/com/azure/autorest/extension/base/util/FileUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
package com.azure.autorest.extension.base.util; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Utility class for file operations. | ||
*/ | ||
public final class FileUtils { | ||
private FileUtils() { | ||
} | ||
|
||
/** | ||
* Creates a temporary directory. | ||
* <p> | ||
* If the environment setting {@code codegen.java.temp.directory} is set, the directory will be created under the | ||
* specified path. Otherwise, the directory will be created under the system default temporary directory. | ||
* <p> | ||
* {@link System#getProperty(String)} is checked before {@link System#getenv(String)}. | ||
* <p> | ||
* If {@code codegen.java.temp.directory} is set to a non-existent path, the directory will be created under the | ||
* system default temporary directory. | ||
* | ||
* @param prefix The prefix string to be used in generating the directory's name; may be {@code null}. | ||
* @return The path to the newly created directory. | ||
* @throws IOException If an I/O error occurs. | ||
*/ | ||
public static Path createTempDirectory(String prefix) throws IOException { | ||
String tempDirectory = System.getProperty("codegen.java.temp.directory"); | ||
if (tempDirectory == null) { | ||
tempDirectory = System.getenv("codegen.java.temp.directory"); | ||
} | ||
|
||
if (tempDirectory != null) { | ||
Path tempDirectoryPath = Paths.get(tempDirectory); | ||
if (Files.exists(tempDirectoryPath)) { | ||
return Files.createTempDirectory(tempDirectoryPath, prefix); | ||
} | ||
} | ||
|
||
return Files.createTempDirectory(prefix); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.