PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/MRI-J/jdk/test/java/io/File/WinDeviceName.java

https://github.com/GregBowyer/ManagedRuntimeInitiative
Java | 57 lines | 27 code | 3 blank | 27 comment | 4 complexity | 8153da49da1316422ff2a6f5fb8a3abc MD5 | raw file
  1. /*
  2. * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation.
  8. *
  9. * This code is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * version 2 for more details (a copy is included in the LICENSE file that
  13. * accompanied this code).
  14. *
  15. * You should have received a copy of the GNU General Public License version
  16. * 2 along with this work; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18. *
  19. * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20. * CA 95054 USA or visit www.sun.com if you need additional information or
  21. * have any questions.
  22. */
  23. /* @test
  24. @bug 6176051
  25. @summary Check isFile's handling of Windows device names
  26. */
  27. import java.io.File;
  28. public class WinDeviceName {
  29. private static String devnames[] = {
  30. "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4",
  31. "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2",
  32. "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
  33. "CLOCK$"
  34. };
  35. public static void main(String[] args) throws Exception {
  36. String osName = System.getProperty("os.name");
  37. if (!osName.startsWith("Windows")) {
  38. return;
  39. }
  40. for (int i = 0; i < devnames.length; i++) {
  41. if (new File(devnames[i]).isFile() ||
  42. new File(devnames[i] + ".txt").isFile()) {
  43. if ("CLOCK$".equals(devnames[i]) &&
  44. (osName.startsWith("Windows 9") ||
  45. osName.startsWith("Windows Me"))) {
  46. //"CLOCK$" is a reserved device name for NT
  47. continue;
  48. }
  49. throw new Exception("isFile() returns true for Device name "
  50. + devnames[i]);
  51. }
  52. }
  53. }
  54. }