Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2014 www.StarNub.org - Underbalanced
  3. *
  4. * This file is part of org.starnub a Java Wrapper for Starbound.
  5. *
  6. * This above mentioned StarNub software is free software:
  7. * you can redistribute it and/or modify it under the terms
  8. * of the GNU General Public License as published by the Free
  9. * Software Foundation, either version 3 of the License, or
  10. * any later version. This above mentioned CodeHome software
  11. * is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  14. * the GNU General Public License for more details. You should
  15. * have received a copy of the GNU General Public License in
  16. * this StarNub Software. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. package org.starnub.utilities.os;
  20.  
  21. import java.io.BufferedReader;
  22. import java.io.IOException;
  23. import java.io.InputStream;
  24. import java.io.InputStreamReader;
  25.  
  26. /**
  27. * Represents a OperatingSystem this will represent some OS
  28. *
  29. * @author Daniel (Underbalanced) (www.StarNub.org)
  30. * @since 1.0
  31. */
  32. public class OperatingSystem {
  33.  
  34. protected final OperatingSystemType OPERATING_SYSTEM;
  35. protected int BIT_VERSION;
  36.  
  37. public OperatingSystem() {
  38. String systemOS = System.getProperty("os.name");
  39. ProcessBuilder processBuilder;
  40. if (systemOS.startsWith("Windows")){
  41. this.OPERATING_SYSTEM = OperatingSystemType.WINDOWS;
  42. processBuilder = getProcessBuilder("cmd.exe", "/c", "wmic OS get OSArchitecture");
  43. } else {
  44. this.OPERATING_SYSTEM = OperatingSystemType.LINUX;
  45. processBuilder = getProcessBuilder("uname -m");
  46. }
  47. setBitVersion(processBuilder);
  48. }
  49.  
  50. public OperatingSystemType getOPERATING_SYSTEM() {
  51. return OPERATING_SYSTEM;
  52. }
  53.  
  54. public int getBIT_VERSION() {
  55. return BIT_VERSION;
  56. }
  57.  
  58. private ProcessBuilder getProcessBuilder(String command){
  59. return new ProcessBuilder(command);
  60. }
  61.  
  62. private ProcessBuilder getProcessBuilder(String... commands){
  63. return new ProcessBuilder(commands);
  64. }
  65.  
  66. private static int setBitVersion(ProcessBuilder pb) {
  67. InputStreamReader isr;
  68. try {
  69. pb.redirectErrorStream(true);
  70. Process p = pb.start();
  71. InputStream is = p.getInputStream();
  72. isr = new InputStreamReader(is);
  73. String line;
  74. StringBuilder sb = new StringBuilder();
  75. try (BufferedReader br = new BufferedReader(isr)) {
  76. while ((line = br.readLine()) != null) {
  77. sb.append(line);
  78. }
  79. line = sb.toString();
  80. if ((line.contains("x86_64") || line.contains("64"))) {
  81. return 64;
  82. }
  83. }
  84. } catch (IOException ioe){
  85. ioe.printStackTrace();
  86. }
  87. return 32;
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement