當前位置: 首頁>>代碼示例>>Java>>正文


Java Validate.validState方法代碼示例

本文整理匯總了Java中org.apache.commons.lang3.Validate.validState方法的典型用法代碼示例。如果您正苦於以下問題:Java Validate.validState方法的具體用法?Java Validate.validState怎麽用?Java Validate.validState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang3.Validate的用法示例。


在下文中一共展示了Validate.validState方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applyServerIconToResponse

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
public void applyServerIconToResponse(ServerStatusResponse response)
{
    File file1 = this.getFile("server-icon.png");

    if (!file1.exists())
    {
        file1 = this.getActiveAnvilConverter().getFile(this.getFolderName(), "icon.png");
    }

    if (file1.isFile())
    {
        ByteBuf bytebuf = Unpooled.buffer();

        try
        {
            BufferedImage bufferedimage = ImageIO.read(file1);
            Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
            Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
            ImageIO.write(bufferedimage, "PNG", (OutputStream)(new ByteBufOutputStream(bytebuf)));
            ByteBuf bytebuf1 = Base64.encode(bytebuf);
            response.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8));
        }
        catch (Exception exception)
        {
            LOG.error((String)"Couldn\'t load server icon", (Throwable)exception);
        }
        finally
        {
            bytebuf.release();
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:33,代碼來源:MinecraftServer.java

示例2: processLoginStart

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
public void processLoginStart(C00PacketLoginStart packetIn)
{
    Validate.validState(this.currentLoginState == NetHandlerLoginServer.LoginState.HELLO, "Unexpected hello packet", new Object[0]);
    this.loginGameProfile = packetIn.getProfile();

    if (this.server.isServerInOnlineMode() && !this.networkManager.isLocalChannel())
    {
        this.currentLoginState = NetHandlerLoginServer.LoginState.KEY;
        this.networkManager.sendPacket(new S01PacketEncryptionRequest(this.serverId, this.server.getKeyPair().getPublic(), this.verifyToken));
    }
    else
    {
        this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:16,代碼來源:NetHandlerLoginServer.java

示例3: addFaviconToStatusResponse

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
private void addFaviconToStatusResponse(ServerStatusResponse response)
{
    File file1 = this.getFile("server-icon.png");

    if (file1.isFile())
    {
        ByteBuf bytebuf = Unpooled.buffer();

        try
        {
            BufferedImage bufferedimage = ImageIO.read(file1);
            Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
            Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
            ImageIO.write(bufferedimage, "PNG", (OutputStream)(new ByteBufOutputStream(bytebuf)));
            ByteBuf bytebuf1 = Base64.encode(bytebuf);
            response.setFavicon("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8));
        }
        catch (Exception exception)
        {
            logger.error((String)"Couldn\'t load server icon", (Throwable)exception);
        }
        finally
        {
            bytebuf.release();
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:28,代碼來源:MinecraftServer.java

示例4: processLoginStart

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
public void processLoginStart(CPacketLoginStart packetIn)
{
    Validate.validState(this.currentLoginState == NetHandlerLoginServer.LoginState.HELLO, "Unexpected hello packet", new Object[0]);
    this.loginGameProfile = packetIn.getProfile();

    if (this.server.isServerInOnlineMode() && !this.networkManager.isLocalChannel())
    {
        this.currentLoginState = NetHandlerLoginServer.LoginState.KEY;
        this.networkManager.sendPacket(new SPacketEncryptionRequest("", this.server.getKeyPair().getPublic(), this.verifyToken));
    }
    else
    {
        this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:16,代碼來源:NetHandlerLoginServer.java

示例5: loadServerIcon

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
private void loadServerIcon()
{
    boolean flag = this.iconFile != null && this.iconFile.isFile();

    if (flag)
    {
        BufferedImage bufferedimage;

        try
        {
            bufferedimage = ImageIO.read(this.iconFile);
            Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
            Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
        }
        catch (Throwable throwable)
        {
            LOGGER.error("Invalid icon for world {}", new Object[] {this.worldSummary.getFileName(), throwable});
            this.iconFile = null;
            return;
        }

        if (this.icon == null)
        {
            this.icon = new DynamicTexture(bufferedimage.getWidth(), bufferedimage.getHeight());
            this.client.getTextureManager().loadTexture(this.iconLocation, this.icon);
        }

        bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), this.icon.getTextureData(), 0, bufferedimage.getWidth());
        this.icon.updateDynamicTexture();
    }
    else if (!flag)
    {
        this.client.getTextureManager().deleteTexture(this.iconLocation);
        this.icon = null;
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:37,代碼來源:GuiListWorldSelectionEntry.java

示例6: assertContextInjected

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
/**
 * 檢查ApplicationContext不為空.
 */
private static void assertContextInjected() {
	Validate.validState(applicationContext != null, "applicaitonContext屬性未注入, 請在applicationContext.xml中定義SpringContextHolder.");
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:7,代碼來源:SpringContextHolder.java

示例7: prepareServerIcon

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
private void prepareServerIcon()
{
    if (this.field_148301_e.getBase64EncodedIconData() == null)
    {
        this.mc.getTextureManager().deleteTexture(this.field_148306_i);
        this.field_148305_h = null;
    }
    else
    {
        ByteBuf bytebuf = Unpooled.copiedBuffer((CharSequence)this.field_148301_e.getBase64EncodedIconData(), Charsets.UTF_8);
        ByteBuf bytebuf1 = Base64.decode(bytebuf);
        BufferedImage bufferedimage;
        label101:
        {
            try
            {
                bufferedimage = TextureUtil.readBufferedImage(new ByteBufInputStream(bytebuf1));
                Validate.validState(bufferedimage.getWidth() == 64, "Must be 64 pixels wide", new Object[0]);
                Validate.validState(bufferedimage.getHeight() == 64, "Must be 64 pixels high", new Object[0]);
                break label101;
            }
            catch (Throwable throwable)
            {
                logger.error("Invalid icon for server " + this.field_148301_e.serverName + " (" + this.field_148301_e.serverIP + ")", throwable);
                this.field_148301_e.setBase64EncodedIconData((String)null);
            }
            finally
            {
                bytebuf.release();
                bytebuf1.release();
            }

            return;
        }

        if (this.field_148305_h == null)
        {
            this.field_148305_h = new DynamicTexture(bufferedimage.getWidth(), bufferedimage.getHeight());
            this.mc.getTextureManager().loadTexture(this.field_148306_i, this.field_148305_h);
        }

        bufferedimage.getRGB(0, 0, bufferedimage.getWidth(), bufferedimage.getHeight(), this.field_148305_h.getTextureData(), 0, bufferedimage.getWidth());
        this.field_148305_h.updateDynamicTexture();
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:46,代碼來源:ServerListEntryNormal.java

示例8: processEncryptionResponse

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
public void processEncryptionResponse(C01PacketEncryptionResponse packetIn)
{
    Validate.validState(this.currentLoginState == NetHandlerLoginServer.LoginState.KEY, "Unexpected key packet", new Object[0]);
    PrivateKey privatekey = this.server.getKeyPair().getPrivate();

    if (!Arrays.equals(this.verifyToken, packetIn.getVerifyToken(privatekey)))
    {
        throw new IllegalStateException("Invalid nonce!");
    }
    else
    {
        this.secretKey = packetIn.getSecretKey(privatekey);
        this.currentLoginState = NetHandlerLoginServer.LoginState.AUTHENTICATING;
        this.networkManager.enableEncryption(this.secretKey);
        (new Thread("User Authenticator #" + AUTHENTICATOR_THREAD_ID.incrementAndGet())
        {
            public void run()
            {
                GameProfile gameprofile = NetHandlerLoginServer.this.loginGameProfile;

                try
                {
                    String s = (new BigInteger(CryptManager.getServerIdHash(NetHandlerLoginServer.this.serverId, NetHandlerLoginServer.this.server.getKeyPair().getPublic(), NetHandlerLoginServer.this.secretKey))).toString(16);
                    NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.server.getMinecraftSessionService().hasJoinedServer(new GameProfile((UUID)null, gameprofile.getName()), s);

                    if (NetHandlerLoginServer.this.loginGameProfile != null)
                    {
                        NetHandlerLoginServer.logger.info("UUID of player " + NetHandlerLoginServer.this.loginGameProfile.getName() + " is " + NetHandlerLoginServer.this.loginGameProfile.getId());
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.logger.warn("Failed to verify username but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Failed to verify username!");
                        NetHandlerLoginServer.logger.error("Username \'" + NetHandlerLoginServer.this.loginGameProfile.getName() + "\' tried to join with an invalid session");
                    }
                }
                catch (AuthenticationUnavailableException var3)
                {
                    if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.logger.warn("Authentication servers are down but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Authentication servers are down. Please try again later, sorry!");
                        NetHandlerLoginServer.logger.error("Couldn\'t verify username because servers are unavailable");
                    }
                }
            }
        }).start();
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:61,代碼來源:NetHandlerLoginServer.java

示例9: processEncryptionResponse

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
public void processEncryptionResponse(CPacketEncryptionResponse packetIn)
{
    Validate.validState(this.currentLoginState == NetHandlerLoginServer.LoginState.KEY, "Unexpected key packet", new Object[0]);
    PrivateKey privatekey = this.server.getKeyPair().getPrivate();

    if (!Arrays.equals(this.verifyToken, packetIn.getVerifyToken(privatekey)))
    {
        throw new IllegalStateException("Invalid nonce!");
    }
    else
    {
        this.secretKey = packetIn.getSecretKey(privatekey);
        this.currentLoginState = NetHandlerLoginServer.LoginState.AUTHENTICATING;
        this.networkManager.enableEncryption(this.secretKey);
        (new Thread("User Authenticator #" + AUTHENTICATOR_THREAD_ID.incrementAndGet())
        {
            public void run()
            {
                GameProfile gameprofile = NetHandlerLoginServer.this.loginGameProfile;

                try
                {
                    String s = (new BigInteger(CryptManager.getServerIdHash("", NetHandlerLoginServer.this.server.getKeyPair().getPublic(), NetHandlerLoginServer.this.secretKey))).toString(16);
                    NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.server.getMinecraftSessionService().hasJoinedServer(new GameProfile((UUID)null, gameprofile.getName()), s, this.func_191235_a());

                    if (NetHandlerLoginServer.this.loginGameProfile != null)
                    {
                        NetHandlerLoginServer.LOGGER.info("UUID of player {} is {}", new Object[] {NetHandlerLoginServer.this.loginGameProfile.getName(), NetHandlerLoginServer.this.loginGameProfile.getId()});
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.LOGGER.warn("Failed to verify username but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Failed to verify username!");
                        NetHandlerLoginServer.LOGGER.error("Username \'{}\' tried to join with an invalid session", new Object[] {gameprofile.getName()});
                    }
                }
                catch (AuthenticationUnavailableException var3)
                {
                    if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.LOGGER.warn("Authentication servers are down but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Authentication servers are down. Please try again later, sorry!");
                        NetHandlerLoginServer.LOGGER.error("Couldn\'t verify username because servers are unavailable");
                    }
                }
            }
            @Nullable
            private InetAddress func_191235_a()
            {
                SocketAddress socketaddress = NetHandlerLoginServer.this.networkManager.getRemoteAddress();
                return NetHandlerLoginServer.this.server.func_190518_ac() && socketaddress instanceof InetSocketAddress ? ((InetSocketAddress)socketaddress).getAddress() : null;
            }
        }).start();
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:67,代碼來源:NetHandlerLoginServer.java

示例10: processEncryptionResponse

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
public void processEncryptionResponse(CPacketEncryptionResponse packetIn)
{
    Validate.validState(this.currentLoginState == NetHandlerLoginServer.LoginState.KEY, "Unexpected key packet", new Object[0]);
    PrivateKey privatekey = this.server.getKeyPair().getPrivate();

    if (!Arrays.equals(this.verifyToken, packetIn.getVerifyToken(privatekey)))
    {
        throw new IllegalStateException("Invalid nonce!");
    }
    else
    {
        this.secretKey = packetIn.getSecretKey(privatekey);
        this.currentLoginState = NetHandlerLoginServer.LoginState.AUTHENTICATING;
        this.networkManager.enableEncryption(this.secretKey);
        (new Thread("User Authenticator #" + AUTHENTICATOR_THREAD_ID.incrementAndGet())
        {
            public void run()
            {
                GameProfile gameprofile = NetHandlerLoginServer.this.loginGameProfile;

                try
                {
                    String s = (new BigInteger(CryptManager.getServerIdHash("", NetHandlerLoginServer.this.server.getKeyPair().getPublic(), NetHandlerLoginServer.this.secretKey))).toString(16);
                    NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.server.getMinecraftSessionService().hasJoinedServer(new GameProfile((UUID)null, gameprofile.getName()), s);

                    if (NetHandlerLoginServer.this.loginGameProfile != null)
                    {
                        NetHandlerLoginServer.LOGGER.info("UUID of player {} is {}", new Object[] {NetHandlerLoginServer.this.loginGameProfile.getName(), NetHandlerLoginServer.this.loginGameProfile.getId()});
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.LOGGER.warn("Failed to verify username but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Failed to verify username!");
                        NetHandlerLoginServer.LOGGER.error("Username \'{}\' tried to join with an invalid session", new Object[] {gameprofile.getName()});
                    }
                }
                catch (AuthenticationUnavailableException var3)
                {
                    if (NetHandlerLoginServer.this.server.isSinglePlayer())
                    {
                        NetHandlerLoginServer.LOGGER.warn("Authentication servers are down but will let them in anyway!");
                        NetHandlerLoginServer.this.loginGameProfile = NetHandlerLoginServer.this.getOfflineProfile(gameprofile);
                        NetHandlerLoginServer.this.currentLoginState = NetHandlerLoginServer.LoginState.READY_TO_ACCEPT;
                    }
                    else
                    {
                        NetHandlerLoginServer.this.closeConnection("Authentication servers are down. Please try again later, sorry!");
                        NetHandlerLoginServer.LOGGER.error("Couldn\'t verify username because servers are unavailable");
                    }
                }
            }
        }).start();
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:61,代碼來源:NetHandlerLoginServer.java

示例11: assertContextInjected

import org.apache.commons.lang3.Validate; //導入方法依賴的package包/類
/**
 * 檢查ApplicationContext不為空.
 */
private static void assertContextInjected() {
    Validate.validState(applicationContext != null, "applicaitonContext屬性未注入, 請在applicationContext.xml中定義SpringContextHolder.");
}
 
開發者ID:liuxx001,項目名稱:bird-java,代碼行數:7,代碼來源:SpringContextHolder.java


注:本文中的org.apache.commons.lang3.Validate.validState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。