1 11 package org.eclipse.core.internal.filesystem; 12 13 import java.io.*; 14 import java.util.Date ; 15 import org.eclipse.core.internal.runtime.RuntimeLog; 16 import org.eclipse.core.runtime.*; 17 18 21 public class Policy { 22 23 26 public static boolean DEBUG = false; 27 28 public static final String PI_FILE_SYSTEM = "org.eclipse.core.filesystem"; 30 public static void checkCanceled(IProgressMonitor monitor) { 31 if (monitor.isCanceled()) 32 throw new OperationCanceledException(); 33 } 34 35 39 public static void debug(String message) { 40 StringBuffer buffer = new StringBuffer (); 41 buffer.append(new Date (System.currentTimeMillis())); 42 buffer.append(" - ["); buffer.append(Thread.currentThread().getName()); 44 buffer.append("] "); buffer.append(message); 46 System.out.println(buffer.toString()); 47 } 48 49 public static void error(int code, String message) throws CoreException { 50 error(code, message, null); 51 } 52 53 public static void error(int code, String message, Throwable exception) throws CoreException { 54 int severity = code == 0 ? 0 : 1 << (code % 100 / 33); 55 throw new CoreException(new Status(severity, PI_FILE_SYSTEM, code, message, exception)); 56 } 57 58 public static void log(int severity, String message, Throwable t) { 59 if (message == null) 60 message = ""; RuntimeLog.log(new Status(severity, PI_FILE_SYSTEM, 1, message, t)); 62 } 63 64 public static IProgressMonitor monitorFor(IProgressMonitor monitor) { 65 return monitor == null ? new NullProgressMonitor() : monitor; 66 } 67 68 71 public static void safeClose(InputStream in) { 72 try { 73 if (in != null) 74 in.close(); 75 } catch (IOException e) { 76 } 78 } 79 80 83 public static void safeClose(OutputStream out) { 84 try { 85 if (out != null) 86 out.close(); 87 } catch (IOException e) { 88 } 90 } 91 92 public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) { 93 if (monitor == null) 94 return new NullProgressMonitor(); 95 if (monitor instanceof NullProgressMonitor) 96 return monitor; 97 return new SubProgressMonitor(monitor, ticks); 98 } 99 } 100 | Popular Tags |