public static void compress(String file, String output) { BinaryOut out = new BinaryOut(output); Node root = buildTrie(new BinaryIn(file)); writeTrie(root, out); out.write(root.frequency); BinaryIn in = new BinaryIn(file); Map<Character, String> huffmanCode = new HashMap<Character, String>(); getHuffmanCode(root, huffmanCode, new StringBuilder()); while(!in.isEmpty()) { char c = in.readChar(); String code = huffmanCode.get(c); for (int i = 0; i < code.length(); i++) { if (code.charAt(i) == '0') { out.write(false); //System.out.println('0'); } else if (code.charAt(i) == '1') { out.write(true); //System.out.println('1'); } else throw new IllegalSelectorException(); } } out.close(); }
public static void throwRandomRuntimeException() { String random = "planb:" + UUID.randomUUID().toString(); RuntimeException[] exceptions = new RuntimeException[]{ new IllegalStateException("This is a test exception because the sate " + random), new IllegalArgumentException("Wrong argument test exception" + random), new RuntimeException("This is a test exception " + random), new IllegalSelectorException(), new IndexOutOfBoundsException("A test index exception " + random), new ClassCastException("A test class cast exception " + random), new NoSuchElementException("A test no such element exception " + random), new MalformedParameterizedTypeException(), new BufferOverflowException(), new EmptyStackException(), new NullPointerException("This is not a real nullpointer " + random), new SecurityException("This is not a real security exception " + random), new ArithmeticException("This is not a real arithmetic exception " + random), new IllegalThreadStateException("This is a test exception with threads " + random), new IllegalCharsetNameException("Charset is wrong test exception " + random), new IllegalMonitorStateException("This is a test exception with illegal monitor " + random)}; throw exceptions[new Random().nextInt(exceptions.length)]; }
/** * As sometimes , make sure the result has one rows. * @param queryObj * @return */ public static QueryOption createMax1Option(ConditionQuery queryObj){ int queryTimeout=queryObj.getQueryTimeout(); String tableName=null; if(queryObj instanceof JoinElement){ tableName=(String)((JoinElement)queryObj).getAttribute(JoinElement.CUSTOM_TABLE_NAME); } if(queryTimeout>0 || tableName!=null){ QueryOption op; try { op = (QueryOption) DEFAULT_MAX1.clone(); } catch (CloneNotSupportedException e) { throw new IllegalSelectorException();//never happens } op.queryTimeout=queryTimeout; return op; }else{ return DEFAULT_MAX1; } }
/** * @tests serialization/deserialization compatibility. */ @TestTargets({ @TestTargetNew( level = TestLevel.COMPLETE, notes = "Verifies serialization/deserialization compatibility.", method = "!SerializationSelf", args = {} ), @TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, notes = "Verifies serialization/deserialization compatibility.", method = "IllegalSelectorException", args = {} ) }) public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new IllegalSelectorException()); }
/** * @tests serialization/deserialization compatibility with RI. */ @TestTargets({ @TestTargetNew( level = TestLevel.COMPLETE, notes = "Verifies serialization/deserialization compatibility.", method = "!SerializationGolden", args = {} ), @TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, notes = "Verifies serialization/deserialization compatibility.", method = "IllegalSelectorException", args = {} ) }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new IllegalSelectorException()); }
protected SelectionKey register(AbstractSelectableChannel channel, int operations, Object attachment) { if (!provider().equals(channel.provider())) { throw new IllegalSelectorException(); } synchronized (this) { synchronized (keysSet) { // System.out.println("Registering channel"); // create the key SelectionKey sk = new EpollSelectionKeyImpl(channel, operations, attachment, this); int index = addKey(sk); ((EpollSelectionKeyImpl) sk).setIndex(index); // System.out.println(" channel registered with index = " + // index); return sk; } } }
/** * @see java.nio.channels.spi.AbstractSelector#register(java.nio.channels.spi.AbstractSelectableChannel, * int, java.lang.Object) */ @Override protected SelectionKey register(AbstractSelectableChannel channel, int operations, Object attachment) { if (!provider().equals(channel.provider())) { throw new IllegalSelectorException(); } synchronized (this) { synchronized (unmodifiableKeys) { // create the key SelectionKeyImpl selectionKey = new SelectionKeyImpl( channel, operations, attachment, this); addKey(selectionKey); mutableKeys.add(selectionKey); return selectionKey; } } }
public static HashSet<MPart> getOpenedEditors(){ EModelService modelService = CloudscaleContext.getGlobalContext().get(EModelService.class); MApplication app = CloudscaleContext.getGlobalContext().get(MApplication.class); if(modelService == null){ throw new IllegalSelectorException(); } if(app == null){ throw new IllegalSelectorException(); } HashSet<MPart> out = new HashSet<MPart>(); MPartStack stack = (MPartStack)modelService.find("org.eclipse.e4.primaryDataStack", app); for(MStackElement el : stack.getChildren()){ if(el instanceof MPart){ MPart part = (MPart)el; if(part.getContext() != null){ out.add(part); } } } return out; }
protected final SelectionKey register(AbstractSelectableChannel ch, int ops, Object attachment) { if (!(ch instanceof SelChImpl)) throw new IllegalSelectorException(); SelectionKeyImpl k = new SelectionKeyImpl((SelChImpl)ch, this); k.attach(attachment); synchronized (publicKeys) { implRegister(k); } k.interestOps(ops); return k; }
/** */ @Override protected SelectionKey register( // final AbstractSelectableChannel channel, // final int interestOps, // final Object attachment // ) { if (registeredKeyMap.size() >= maximimSelectorSize) { throw new IllegalSelectorException(); } if (!(channel instanceof ChannelUDT)) { throw new IllegalSelectorException(); } final ChannelUDT channelUDT = (ChannelUDT) channel; final Integer socketId = channelUDT.socketUDT().id(); SelectionKeyUDT keyUDT = registeredKeyMap.get(socketId); if (keyUDT == null) { keyUDT = new SelectionKeyUDT(this, channelUDT, attachment); registeredKeyMap.putIfAbsent(socketId, keyUDT); keyUDT = registeredKeyMap.get(socketId); } keyUDT.interestOps(interestOps); return keyUDT; }
@Override public void park(char carType) { if (!isFree()) { throw new IllegalSelectorException(); } this.carType = carType; }
@Override protected SelectionKey register(AbstractSelectableChannel channel, int operations, Object attachment) { if (!provider().equals(channel.provider())) { throw new IllegalSelectorException(); } synchronized (this) { synchronized (unmodifiableKeys) { SelectionKeyImpl selectionKey = new SelectionKeyImpl(channel, operations, attachment, this); mutableKeys.add(selectionKey); ensurePollFdsCapacity(); return selectionKey; } } }
/** * Registers this channel with the specified selector for the specified * interest set. If the channel is already registered with the selector, the * {@link SelectionKey interest set} is updated to {@code interestSet} and * the corresponding selection key is returned. If the channel is not yet * registered, this method calls the {@code register} method of * {@code selector} and adds the selection key to this channel's key set. * * @param selector * the selector with which to register this channel. * @param interestSet * this channel's {@link SelectionKey interest set}. * @param attachment * the object to attach, can be {@code null}. * @return the selection key for this registration. * @throws CancelledKeyException * if this channel is registered but its key has been canceled. * @throws ClosedChannelException * if this channel is closed. * @throws IllegalArgumentException * if {@code interestSet} is not supported by this channel. * @throws IllegalBlockingModeException * if this channel is in blocking mode. * @throws IllegalSelectorException * if this channel does not have the same provider as the given * selector. */ @Override public final SelectionKey register(Selector selector, int interestSet, Object attachment) throws ClosedChannelException { if (!isOpen()) { throw new ClosedChannelException(); } if (!((interestSet & ~validOps()) == 0)) { throw new IllegalArgumentException("no valid ops in interest set: " + interestSet); } synchronized (blockingLock) { if (isBlocking) { throw new IllegalBlockingModeException(); } if (!selector.isOpen()) { if (interestSet == 0) { // throw ISE exactly to keep consistency throw new IllegalSelectorException(); } // throw NPE exactly to keep consistency throw new NullPointerException("selector not open"); } SelectionKey key = keyFor(selector); if (key == null) { key = ((AbstractSelector) selector).register(this, interestSet, attachment); keyList.add(key); } else { if (!key.isValid()) { throw new CancelledKeyException(); } key.interestOps(interestSet); key.attach(attachment); } return key; } }
public static QueryOption createOption(){ try { return (QueryOption) DEFAULT.clone(); } catch (CloneNotSupportedException e) { throw new IllegalSelectorException();//never happens } }
/** * Registers this channel with the specified selector for the specified * interest set. If the channel is already registered with the selector, the * {@link SelectionKey interest set} is updated to {@code interestSet} and * the corresponding selection key is returned. If the channel is not yet * registered, this method calls the {@code register} method of * {@code selector} and adds the selection key to this channel's key set. * * @param selector * the selector with which to register this channel. * @param interestSet * this channel's {@link SelectionKey interest set}. * @param attachment * the object to attach, can be {@code null}. * @return the selection key for this registration. * @throws CancelledKeyException * if this channel is registered but its key has been canceled. * @throws ClosedChannelException * if this channel is closed. * @throws IllegalArgumentException * if {@code interestSet} is not supported by this channel. * @throws IllegalBlockingModeException * if this channel is in blocking mode. * @throws IllegalSelectorException * if this channel does not have the same provider as the given * selector. */ @Override public final SelectionKey register(Selector selector, int interestSet, Object attachment) throws ClosedChannelException { if (!isOpen()) { throw new ClosedChannelException(); } if (!((interestSet & ~validOps()) == 0)) { throw new IllegalArgumentException(); } synchronized (blockingLock) { if (isBlocking) { throw new IllegalBlockingModeException(); } if (!selector.isOpen()) { if (0 == interestSet) { // throw ISE exactly to keep consistency throw new IllegalSelectorException(); } // throw NPE exactly to keep consistency throw new NullPointerException(); } SelectionKey key = keyFor(selector); if (null == key) { key = ((AbstractSelector) selector).register(this, interestSet, attachment); keyList.add(key); } else { if (!key.isValid()) { throw new CancelledKeyException(); } key.interestOps(interestSet); key.attach(attachment); } return key; } }
@Override protected SelectionKey register(AbstractSelectableChannel channel, int operations, Object attachment) { if (!provider().equals(channel.provider())) { throw new IllegalSelectorException(); } synchronized (this) { synchronized (unmodifiableKeys) { SelectionKeyImpl selectionKey = new SelectionKeyImpl( channel, operations, attachment, this); mutableKeys.add(selectionKey); return selectionKey; } } }
/** * @tests {@link java.nio.channels.IllegalSelectorException#IllegalSelectorException()} */ public void test_Constructor() { IllegalSelectorException e = new IllegalSelectorException(); assertNull(e.getMessage()); assertNull(e.getLocalizedMessage()); assertNull(e.getCause()); }
@Override public SelectionKey register(Selector selector, int operation, Object attachment) throws IOException { if (isBlocking()) throw new IllegalBlockingModeException(); if (provider() != selector.provider()) throw new IllegalSelectorException(); SelectionKey key = ((SelectorImpl)selector).register(this, operation, attachment); keys.put(selector,key); return key; }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAllByInvalidRackId() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); List< SettopDesc > settops = settopDomainService.findAllByRackId( DataProvider.INVALID_ID ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAvailableByInvalidRackId() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); List< SettopDesc > settops = settopDomainService.findAllByRackId( DataProvider.INVALID_ID ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAllByInvalidReservationId() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); List< SettopDesc > settops = settopDomainService.findAllByReservationId( DataProvider.INVALID_ID ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAvailableByInvalidReservationId() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); List< SettopDesc > settops = settopDomainService.findAllByReservationId( DataProvider.INVALID_ID ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAllByInvalidReservationName() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); Reservation reservation = new Reservation(); reservation.setName( DataProvider.INVALID_NAME ); List< SettopDesc > settops = settopDomainService.findAllByReservation( reservation ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAvailableByInvalidReservationName() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); Reservation reservation = new Reservation(); reservation.setName( DataProvider.INVALID_NAME ); List< SettopDesc > settops = settopDomainService.findAllByReservation( reservation ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAllByInvalidSettopGroupName() throws SettopNotFoundException { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); SettopGroup settopGroup = new SettopGroup(); settopGroup.setName( DataProvider.INVALID_NAME ); List< SettopDesc > settops = settopDomainService.findAllBySettopGroup( settopGroup ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAvailableByInvalidSettopGroupName() throws SettopNotFoundException { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); SettopGroup settopGroup = new SettopGroup(); settopGroup.setName( DataProvider.INVALID_NAME ); List< SettopDesc > settops = settopDomainService.findAllBySettopGroup( settopGroup ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAllByInvalidRackName() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); Rack rack = new Rack(); rack.setName( DataProvider.INVALID_NAME ); List< SettopDesc > settops = settopDomainService.findAllByRack( rack ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAvailableByInvalidRackName() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); Rack rack = new Rack(); rack.setName( DataProvider.INVALID_NAME ); List< SettopDesc > settops = settopDomainService.findAllByRack( rack ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAllByInvalidSettopGroupId() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( DataProvider.INVALID_ID ); logResult( settops.size() ); }
@SuppressWarnings( { "rawtypes", "unchecked" } ) @Test( expected = RuntimeException.class ) public void findAvailableByInvalidSettopGroupId() { EasyMock.expect( restTemplateMock.getForObject( ( String ) EasyMock.notNull(), ( Class ) EasyMock.notNull() ) ) .andThrow( new IllegalSelectorException() ); replayAll(); List< SettopDesc > settops = settopDomainService.findAllBySettopGroupId( DataProvider.INVALID_ID ); logResult( settops.size() ); }
public static HashSet<IEditorInputResource> getOpenedAlternatives(){ EModelService modelService = CloudscaleContext.getGlobalContext().get(EModelService.class); MApplication app = CloudscaleContext.getGlobalContext().get(MApplication.class); if(modelService == null){ throw new IllegalSelectorException(); } if(app == null){ throw new IllegalSelectorException(); } HashSet<IEditorInputResource> out = new HashSet<IEditorInputResource>(); MPartStack stack = (MPartStack)modelService.find("org.eclipse.e4.primaryDataStack", app); for(MStackElement el : stack.getChildren()){ if(el instanceof MPart){ MPart part = (MPart)el; if(part.getContext() != null){ IEditorInputResource alternative = part.getContext().get(IEditorInputResource.class); if(alternative != null){ out.add(alternative); } } } } return out; }
protected SelectionKey register(AbstractSelectableChannel channel, int operations, Object attachment) { if (!provider().equals(channel.provider())) { throw new IllegalSelectorException(); } synchronized (this) { synchronized (keys) { SelectionKey sk = new SelectionKeyImpl(channel, operations, attachment, this); keys.add(sk); return sk; } } }
@Override public void setContentType(String contentType) { if (isCommitted() || isIncluding()) return; if (contentType == null) { if (isWriting() && _characterEncoding != null) throw new IllegalSelectorException(); if (_locale == null) _characterEncoding = null; _mimeType = null; _contentType = null; _fields.remove(HttpHeader.CONTENT_TYPE); } else { _contentType = contentType; _mimeType = MimeTypes.CACHE.get(contentType); String charset; if (_mimeType!=null && _mimeType.getCharset()!=null && !_mimeType.isCharsetAssumed()) charset=_mimeType.getCharsetString(); else charset = MimeTypes.getCharsetFromContentType(contentType); if (charset == null) { if (_characterEncoding != null) { _contentType = contentType + ";charset=" + _characterEncoding; _mimeType = null; } } else if (isWriting() && !charset.equalsIgnoreCase(_characterEncoding)) { // too late to change the character encoding; _mimeType = null; _contentType = MimeTypes.getContentTypeWithoutCharset(_contentType); if (_characterEncoding != null) _contentType = _contentType + ";charset=" + _characterEncoding; } else { _characterEncoding = charset; _explicitEncoding = true; } if (HttpGenerator.__STRICT || _mimeType==null) _fields.put(HttpHeader.CONTENT_TYPE, _contentType); else { _contentType=_mimeType.asString(); _fields.put(_mimeType.getContentTypeField()); } } }
@Override public void nextStep() { if(!hasNextStep()) throw new IllegalSelectorException(); setCurrentStep(steps[++currStepIndex]); }