小编Dan*_*lor的帖子

如何检查套接字的输出流是否已关闭?

我有这个代码:

public void post(String message) {
    output.close();
    final String mess = message;
    (new Thread() {
        public void run() {
            while (true) {
                try {
                    output.println(mess);
                    System.out.println("The following message was successfully sent:");
                    System.out.println(mess);
                    break;
                } catch (NullPointerException e) {
                    try {Thread.sleep(1000);} catch (InterruptedException ie) {}
                }
            }
        }
    }).start();
}
Run Code Online (Sandbox Code Playgroud)

如您所见,我在代码的最开头关闭套接字,然后try使用它将一些信息发送到另一台计算机.该程序写道:"以下消息已成功发送".这意味着没有抛出NullPointerException.

那么,如果Java尝试使用套接字的封闭输出流,那么它是否会抛出异常?有没有办法检查套接字是关闭还是打开?

添加

我通过以下方式初始化套接字:

clientSideSocket = new Socket(hostname,port);
PrintWriter out = new PrintWriter(clientSideSocket.getOutputStream(), true);
browser.output = out;
Run Code Online (Sandbox Code Playgroud)

java sockets networking outputstream

3
推荐指数
1
解决办法
6491
查看次数

构造函数链接Java

我对构造函数链接程序的输出有轻微疑问,我在下面展示:

class Cube {

    int length;
    int breadth;
    int height;
    public int getVolume() {
        return (length * breadth * height);
    }
    Cube() {
        this(10, 10);
        System.out.println("Finished with Default Constructor of Cube");
    }
    Cube(int l, int b) {
        this(l, b, 10);
        System.out.println("Finished with Parameterized Constructor having
                                    2 params of Cube");
    }
    Cube(int l, int b, int h) {
        length = l;
        breadth = b;
        height = h;
        System.out.println("Finished with Parameterized Constructor having
                                    3 params of Cube");
    }
}

public class SpecialCube …
Run Code Online (Sandbox Code Playgroud)

java methods class

3
推荐指数
1
解决办法
2万
查看次数

Webservice响应命名空间与WSDL定义不匹配

我正在尝试使用JAX-WS连接到Web服务,JAX-WS的WSDL定义与从Web服务收到的实际响应不完全匹配.基本上,WSDL指示所有元素都是"urn:HPD_IncidentInterface_WS"命名空间的一部分,但实际的响应元素位于"urn:Port"命名空间中.这会导致JAX-WS抛出以下异常:

com.sun.xml.internal.ws.streaming.XMLStreamReaderException:意外的XML标记.预期:{urn:HPD_IncidentInterface_WS} HelpDesk_QueryList_ServiceResponse但找到:{urn:Port} HelpDesk_QueryList_ServiceResponse

我解决此问题的计划是下载WSDL,修改它以匹配实际响应中的命名空间,然后使用wsimport重新生成JAX-WS代码.但是,我很难弄清楚如何修改WSDL以使响应命名空间正确.基于我到目前为止所研究的内容,看起来我需要使用包含urn:port targetNamespace的wsdl:definition创建一个新的WSDL文件,然后将其导入到原始的WSDL文件中,但我不能似乎正确的语法.任何人都可以帮我纠正WSDL以匹配实际的Web服务响应吗?

以下是引用urn:Port命名空间的响应示例:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns0:HelpDesk_QueryList_ServiceResponse xmlns:ns0="urn:Port">
         <ns0:getListValues>
            <ns0:Assigned_Group>APP-eBiz-EP-L2</ns0:Assigned_Group>
            <ns0:Assigned_Group_Shift_Name/>
            <ns0:Assigned_Support_Company>Acme</ns0:Assigned_Support_Company>
            <ns0:Assigned_Support_Organization>Applications - eBusinessServices</ns0:Assigned_Support_Organization>
            <ns0:Assignee>Geoff Denning</ns0:Assignee>
            <ns0:Categorization_Tier_1>Issue</ns0:Categorization_Tier_1>
            <ns0:Categorization_Tier_2>Failure</ns0:Categorization_Tier_2>
            <ns0:Categorization_Tier_3/>
            <ns0:City>Mountain View</ns0:City>
            <ns0:Closure_Manufacturer/>
            <ns0:Closure_Product_Category_Tier1/>
            <ns0:Closure_Product_Category_Tier2/>
            <ns0:Closure_Product_Category_Tier3/>
            <ns0:Closure_Product_Model_Version/>
            <ns0:Closure_Product_Name/>
            <ns0:Company>Acme</ns0:Company>
            <ns0:Contact_Company>Acme</ns0:Contact_Company>
            <ns0:Contact_Sensitivity>Standard</ns0:Contact_Sensitivity>
            <ns0:Country>United States</ns0:Country>
            <ns0:Department>Mgmt Information Systems</ns0:Department>
            <ns0:Summary>Test summary</ns0:Summary>
            <ns0:Notes>Refer to the attached error screenshot.</ns0:Notes>
            <ns0:First_Name>Geoff</ns0:First_Name>
            <ns0:Impact>4-Minor/Localized</ns0:Impact>
            <ns0:Incident_Number>INC000000773346</ns0:Incident_Number>
            <ns0:Internet_E-mail>geoff@acme.com</ns0:Internet_E-mail>
            <ns0:Last_Name>Denning</ns0:Last_Name>
            <ns0:Manufacturer/>
            <ns0:Middle_Initial/>
            <ns0:Organization>IT-eBusiness</ns0:Organization>
            <ns0:Phone_Number>000-0000</ns0:Phone_Number>
            <ns0:Priority>Low</ns0:Priority>
            <ns0:Priority_Weight>2</ns0:Priority_Weight>
            <ns0:Product_Categorization_Tier_1>Software-Application</ns0:Product_Categorization_Tier_1>
            <ns0:Product_Categorization_Tier_2>eBusiness Services</ns0:Product_Categorization_Tier_2>
            <ns0:Product_Categorization_Tier_3>Test</ns0:Product_Categorization_Tier_3>
            <ns0:Product_Model_Version/>
            <ns0:Product_Name/>
            <ns0:Region>Americas</ns0:Region>
            <ns0:Reported_Source>Email</ns0:Reported_Source>
            <ns0:Resolution/>
            <ns0:Resolution_Category/>
            <ns0:Resolution_Category_Tier_2/>
            <ns0:Resolution_Category_Tier_3/>
            <ns0:Service_Type>User Service Restoration</ns0:Service_Type>
            <ns0:Site>Mountain View, …
Run Code Online (Sandbox Code Playgroud)

java websphere wsdl web-services jax-ws

3
推荐指数
1
解决办法
2万
查看次数

Eclipse:如何格式化工作区中的所有xml文件?

我非常感谢Eclipse将代码格式化程序应用于工作空间中的所有项目的功能,但它仅适用于Java文件,我现在想将格式化程序应用于所有XML文件.还有一包它们:pom's,Spring configs等.

我发现没有可以为所有选定项目执行任务的内置格式.所以,我的问题,你知道一个外部插件可以完成任务(可能有自己的格式设置,可以导出/导入)?或者我错过了现有选项?

xml eclipse formatting

3
推荐指数
1
解决办法
1463
查看次数

如何在python中将字符串拆分成段

我有一个由几个段构建的字符串,它们没有分开,但没有重叠.这看起来像这样:

<python><regex><split>
Run Code Online (Sandbox Code Playgroud)

我想分成:

<python>, <regex>, <split>
Run Code Online (Sandbox Code Playgroud)

我正在寻找最有效的方法来做到这一点,同时尽可能少的代码.我可以将'>'更改为'>'等,但我不想做任何冗余操作.是否可以使用正则表达式来做到这一点?

python string

3
推荐指数
1
解决办法
583
查看次数

Dojo自定义构建:要部署的文件

首先,我们是Dojo的新手并且是以"新"的方式自由地做事,所以我大多忽略了文档的前1.7部分.不过,在比较各种文章,文档和示例脚本时,我会感到困惑.

最重要的是,我找不到关于如何为Dojo 创建和部署自定义构建的直截了当的说明.更具体地说,我们需要部署哪些.js和.css文件.有很多关于创建构建文档,但是我在部署时没有找到.

我最终收集了将所有内容构建到单个dojo.js是一个合理的移动实践,我只需要从构建目录中提取一个文件并将其部署到我的服务器,但后来我得到了缺少的CSS引用,看起来好像试错法是解决这些问题的正确方法.

这是我们具体的当前案例:

<script type="text/javascript">
        require(
                // deviceTheme to auto-detect device styles
                [   
                    "dojox/mobile",
                    "dojox/mobile/parser",
                    "dojox/mobile/deviceTheme"
                ]);
</script>
Run Code Online (Sandbox Code Playgroud)

这是构建配置文件:

dependencies = {
    stripConsole: "normal",

    layers: [
        {
            name: "dojo.js",
            customBase: true,    // prevent automatic inclusion of dojo/main
            dependencies: [
                "dojox.mobile.parser",
                "dojox.mobile",
                "dojox.mobile.deviceTheme"
            ]
        }
    ],

    prefixes: [
        [ "dijit", "../dijit" ],    // example included; not clear why
        [ "dojox", "../dojox" ]
    ]
}
Run Code Online (Sandbox Code Playgroud)

(由dojo-release-1.7.2-src\dojox\mobile\build\build.bat脚本执行.)

所以我想具体的问题是:

  1. 我为此案例部署了哪些CSS文件?
  2. 我如何知道哪些文件(包括CSS文件)要部署?
  3. 我缺少一个好的,当前的教程吗?
  4. 现有脚本是最新的吗?例如,为什么不mobile-all.profile.js …

dojo dojox.mobile

3
推荐指数
1
解决办法
2046
查看次数

使用javascript查找xml属性值

如何使用Javascript / jQuery获取XML节点的属性值?

我正在尝试获取节点上的duration属性的值,然后获取fixedValue。

<loanAmount>
    <interestRates>
        <interestRate allowInterestOnly="true" type="variable" value="5.82"/>
        <interestRate allowFixed="true" allowInterestOnly="true" duration="1" fixedInterestOnlyValue="5.7" fixedValue="5.7" variableInterestOnlyValue="5.82"/>
        <interestRate allowFixed="true" allowInterestOnly="true" duration="3" fixedInterestOnlyValue="5.75" fixedValue="5.75" variableInterestOnlyValue="5.82"/>
        <interestRate allowFixed="true" allowInterestOnly="true" duration="5" fixedInterestOnlyValue="6.64" fixedValue="6.56" variableInterestOnlyValue="5.82"/>
        <interestRate allowFixed="true" allowInterestOnly="true" duration="10" variableInterestOnlyValue="5.82"/>
    </interestRates>
</loanAmount>'
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经:

var currentLoanRates = function() {
    var currLoanXml = '<loanAmount><interestRates><interestRate allowInterestOnly="true" type="variable" value="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="1" fixedInterestOnlyValue="5.7" fixedValue="5.7" variableInterestOnlyValue="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="3" fixedInterestOnlyValue="5.75" fixedValue="5.75" variableInterestOnlyValue="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="5" fixedInterestOnlyValue="6.64" fixedValue="6.56" variableInterestOnlyValue="5.82"/><interestRate allowFixed="true" allowInterestOnly="true" duration="10" variableInterestOnlyValue="5.82"/></interestRates></loanAmount>',
    xmlDoc = $.parseXML( currLoanXml ),
    $xml = …
Run Code Online (Sandbox Code Playgroud)

javascript xml jquery xml-parsing

3
推荐指数
1
解决办法
1万
查看次数

如何防止取消对话框上的表单验证?

我有一个对话框,使用以下按钮关闭:

<p:commandButton
onclick="propertyEditDialog.hide(),propertyEditDialog.loaded=false" 
value="#{i18n['button.cancel']}" ajax="true"/>
Run Code Online (Sandbox Code Playgroud)

没有动作,只有客户端javascript只是隐藏对话框.但是,我在日志中看到,表单在取消时已经过验证.我已经设置了ajax="true"防止表单验证,但无论如何它都没有帮助.

在没有验证表单的情况下关闭PrimeFaces中对话框的正确方法是什么?

validation primefaces

3
推荐指数
2
解决办法
5654
查看次数

PrimeFaces DataTable InCell编辑 - 非平凡的验证

我想在DataTable中使用InCell编辑和验证.我知道使用f:validator可以解决这些琐碎的验证,但是对于非平凡的名称有什么用?

我必须说,我必须确保表中的'name'属性是唯一的.因此,在接受编辑之前,我应检查名称是否已更改以及是否由其他元素使用.如果是这样,则必须拒绝编辑.

怎么实现呢?正如我所理解的那样,eventListener只会被通知接受编辑,因此理论上我可以做出反应并将其还原,但我宁愿在用户点击"接受"图标时拒绝编辑.

validation datatable jsf primefaces

3
推荐指数
1
解决办法
6449
查看次数

CoreBluetooth框架和IOBluetooth框架之间的区别

什么是CoreBluetooth框架和IOBluetooth框架(用于MAC应用程序)之间的区别?

xcode bluetooth bluetooth-lowenergy

3
推荐指数
1
解决办法
1977
查看次数