equal
deleted
inserted
replaced
98 throws IOException |
98 throws IOException |
99 { |
99 { |
100 // validate arguments before request to poller |
100 // validate arguments before request to poller |
101 if (dir == null) |
101 if (dir == null) |
102 throw new NullPointerException(); |
102 throw new NullPointerException(); |
103 if (events.length == 0) |
|
104 throw new IllegalArgumentException("No events to register"); |
|
105 Set<WatchEvent.Kind<?>> eventSet = new HashSet<>(events.length); |
103 Set<WatchEvent.Kind<?>> eventSet = new HashSet<>(events.length); |
106 for (WatchEvent.Kind<?> event: events) { |
104 for (WatchEvent.Kind<?> event: events) { |
107 // standard events |
105 // standard events |
108 if (event == StandardWatchEventKinds.ENTRY_CREATE || |
106 if (event == StandardWatchEventKinds.ENTRY_CREATE || |
109 event == StandardWatchEventKinds.ENTRY_MODIFY || |
107 event == StandardWatchEventKinds.ENTRY_MODIFY || |
112 eventSet.add(event); |
110 eventSet.add(event); |
113 continue; |
111 continue; |
114 } |
112 } |
115 |
113 |
116 // OVERFLOW is ignored |
114 // OVERFLOW is ignored |
117 if (event == StandardWatchEventKinds.OVERFLOW) { |
115 if (event == StandardWatchEventKinds.OVERFLOW) |
118 if (events.length == 1) |
|
119 throw new IllegalArgumentException("No events to register"); |
|
120 continue; |
116 continue; |
121 } |
|
122 |
117 |
123 // null/unsupported |
118 // null/unsupported |
124 if (event == null) |
119 if (event == null) |
125 throw new NullPointerException("An element in event set is 'null'"); |
120 throw new NullPointerException("An element in event set is 'null'"); |
126 throw new UnsupportedOperationException(event.name()); |
121 throw new UnsupportedOperationException(event.name()); |
127 } |
122 } |
|
123 if (eventSet.isEmpty()) |
|
124 throw new IllegalArgumentException("No events to register"); |
128 return (WatchKey)invoke(RequestType.REGISTER, dir, eventSet, modifiers); |
125 return (WatchKey)invoke(RequestType.REGISTER, dir, eventSet, modifiers); |
129 } |
126 } |
130 |
127 |
131 /** |
128 /** |
132 * Cancels, and waits on, poller thread to cancel given key. |
129 * Cancels, and waits on, poller thread to cancel given key. |