cleanup (inspection "Java | Class structure | Utility class is not 'final'")
[idea/community.git] / platform / util-rt / src / com / intellij / util / ReadEnv.java
1 // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
2 package com.intellij.util;
3
4 import java.io.BufferedWriter;
5 import java.io.FileOutputStream;
6 import java.io.OutputStreamWriter;
7 import java.io.Writer;
8 import java.util.Map;
9
10 public final class ReadEnv {
11   public static void main(String[] args) throws Exception {
12     if (args.length != 1) throw new Exception("Exactly one argument expected");
13
14     Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(args[0]), "UTF-8"));
15     try {
16       for (Map.Entry<String, String> each : System.getenv().entrySet()) {
17         // on Windows Java getenv() includes variables that start from '='.
18         // These variables are not available available in normal command environment.
19
20         // https://stackoverflow.com/questions/30102750/java-system-getenv-environment-names-starting-with
21         if (each.getKey().startsWith("=")) continue;
22
23         out.write(each.getKey());
24         out.write("=");
25         out.write(each.getValue());
26         out.write("\0");
27       }
28     }
29     finally {
30       out.close();
31     }
32   }
33 }