小编ka3*_*3ak的帖子

Windows控制台中的unicode字符比预期的多

我想在Windows控制台中打印俄语和德语字符.所以我写了一个小测试程序来了解它的工作原理:

PrintStream ps = new PrintStream(System.out, false, "UTF-8");
ps.println("öäüß ????");
Run Code Online (Sandbox Code Playgroud)

然后我启动了cmd.exe,将其字体改为Lucida Console,它支持Unicode,用"chcp 65001"将代码页改为Unicode,并执行了我的程序.

打印出德语和俄语字符,但文字比我预期的要多一些(用红色加下划线): 在此输入图像描述

但是文本在Eclipse控制台中正确打印.有没有办法在Windows控制台中正确打印?我使用Windows 7.

我刚刚用JNI解决了这个问题,但它是否可以用纯java来解决它仍然很有趣.

java windows unicode console

9
推荐指数
1
解决办法
563
查看次数

java.lang.IndexOutOfBoundsException:setSpan(N ... N)结束于长度10500

我打电话时遇到这个异常 EditText.setSelection()

java.lang.IndexOutOfBoundsException: setSpan (N ... N) ends beyond length 10500
Run Code Online (Sandbox Code Playgroud)

N可以是任何数字。例如,如果我叫setSelection(10476,10568)N将为10568。但它10500是常数。

          java.lang.IndexOutOfBoundsException: setSpan (10568 ... 10568) ends beyond length 10500
              at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1090)
              at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:665)
              at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:658)
              at android.text.Selection.setSelection(Selection.java:78)
              at android.widget.EditText.setSelection(EditText.java:91)
...
Run Code Online (Sandbox Code Playgroud)

这是否有任何限制EditText

在进行选择之前,我加载了一个文本文件,该文件肯定包含10500多个字符,因为它包含ca。12000行。然后,我打电话EditText.setText()将文件内容放入字段中。EditText.setText()可以正常工作。首先,我认为文件内容有问题,但是我加载了另一个文件,当选择发生时,我遇到了相同的异常,并且其中包含ends beyond length 10500

java android android-edittext

6
推荐指数
1
解决办法
5325
查看次数

用户关闭 Eclipse 应用程序时如何完成作业

我使用 org.eclipse.core.runtime.jobs.Job 执行删除数据的存储过程并根据新数据更新用户界面。因此,即使用户关闭 Eclipse 应用程序,这项工作也将完成,这一点很重要。

final Job execStoredProcJob = new Job(taskName) {
    protected IStatus run(IProgressMonitor monitor) {
        monitor.beginTask(taskName, 
// execute stored procedure
// update user interface
        monitor.done();
        return Status.OK_STATUS;
    }
};

execStoredProcJob.schedule();
Run Code Online (Sandbox Code Playgroud)

当我在作业仍在运行时关闭 eclipse 应用程序时,它似乎会终止作业。用户关闭 eclipse 应用程序后如何完成工作?是否可以?

java eclipse jobs

5
推荐指数
1
解决办法
2649
查看次数

如何在JTextPane中的组件周围包装文本?

我不理解JTextPane中的包装行为.如果我插入一个短文本,然后是一个JComponent然后再短文本我可以在一行中看到插入的东西,如果框架当然足够大.但是如果文本更长,那么它需要几行,组件总是放在一个新行中.

我已经认识到,在将一个组件插入JTextPane后,它的文本会变长一个字符.因此,如果一个组件被JTextPane视为一个字符,为什么它不像一个字符呢?可能它取决于java版本?我使用Java(TM)SE运行时环境(版本1.7.0-b147)

下面是我的代码(使用shortText/longText实例化变量currentText以重现上述行为):

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;

public class Test {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        JTextPane textPane = new JTextPane();
        textPane.setContentType("text/html");

        String shortText = "one two three four five six seven";
        String longText = "A text component that can be marked up with attributes that are represented graphically. You can find how-to information and examples of using text panes in Using Text Components, a …
Run Code Online (Sandbox Code Playgroud)

java swing insert jtextpane jcomponent

5
推荐指数
1
解决办法
1138
查看次数

使用测试容器时“未找到可链接容器”

我想使用测试容器(https://www.testcontainers.org/usage.html

于是我导入了对应的Maven依赖:

<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>testcontainers</artifactId>
    <version>1.10.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>oracle-xe</artifactId>
    <version>1.10.1</version>
    <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

然后我右键单击任务栏上的 docker 图标 -> 设置 -> 常规并检查该项目:

Expose daemon on tcp://localhost:2375 without TLS
Run Code Online (Sandbox Code Playgroud)

按照 testcontainers 站点上的说明设置环境变量:

DOCKER_CERT_PATH=C:\Users\username\.docker
DOCKER_HOST=https://localhost:2375
DOCKER_TLS_VERIFY=1
Run Code Online (Sandbox Code Playgroud)

并使用以下代码创建了 JUnit 测试:

@Test
public void test() {
   OracleContainer oracleXE = new OracleContainer();
...
Run Code Online (Sandbox Code Playgroud)

但是我得到了错误:

Error:(82, 27) java: cannot access org.testcontainers.containers.traits.LinkableContainer
  class file for org.testcontainers.containers.traits.LinkableContainer not found
Run Code Online (Sandbox Code Playgroud)

我在谷歌上搜索了“linkablecontainer not found”和“org.testcontainers.containers.traits.LinkableContainer not found”,但没有结果。

有什么想法出了什么问题吗?

java docker testcontainers

5
推荐指数
1
解决办法
516
查看次数

Swagger Maven 插件不生成操作和模型

我有一个 Spring Boot 应用程序并使用来自https://github.com/kongchen/swagger-maven-plugin的 Swagger Maven 插件

pom.xml中的配置如下:

        <plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <version>3.1.8</version>
            <configuration>
                <apiSources>
                    <apiSource>
                        <attachSwaggerArtifact>true</attachSwaggerArtifact>
                        <outputFormats>json</outputFormats>
                        <locations>package.with.apis</locations>
                        <schemes>
                            <scheme>http</scheme>
                            <scheme>https</scheme>
                        </schemes>
                        <host>localhost:8083</host>
                        <basePath>/api</basePath>
                        <info>
                            <title>Your API name</title>
                            <version>v2</version>
                            <description>Description of your API</description>
                        </info>
                        <swaggerDirectory>generated/swagger-ui</swaggerDirectory>
                    </apiSource>
                </apiSources>
            </configuration>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

<locations>package.with.apis</locations>是包含所有标记为的接口的包@Api

<swaggerDirectory>generated/swagger-ui</swaggerDirectory>swagger.json是生成的落地目录

但生成的不包含、DTO 模型等swagger.json中的信息。@ApiOperation, @ApiResponses

它似乎只包含以下值@Api(tags = {"API ..."})

以下是其摘录:

{
  "swagger" : "2.0",
  "info" : {
    "description" : "Description of your API",
    "version" …
Run Code Online (Sandbox Code Playgroud)

java maven swagger

5
推荐指数
0
解决办法
2240
查看次数

如何垂直居中JTextPane中的文本和JComponent?

目前它看起来如此

在此输入图像描述

怎么做它看起来如此?

在此输入图像描述

以下是我的代码:

    JFrame f = new JFrame();
    JTextPane textPane = new JTextPane();

    JTextField component = new JTextField("      ");
    component.setMaximumSize(component.getPreferredSize());
    textPane.setSelectionStart(textPane.getDocument().getLength());
    textPane.setSelectionEnd(textPane.getDocument().getLength());
    textPane.insertComponent(component);
    try {
        textPane.getDocument().insertString(textPane.getDocument().getLength(), "text",
            new SimpleAttributeSet());
    } catch (BadLocationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    f.add(new JScrollPane(textPane));
    f.setSize(200, 100);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
Run Code Online (Sandbox Code Playgroud)

我发现接近这个主题的单个问题:JTextPane插入组件,错误的垂直对齐 但是如何更改对齐没有答案.但根据那里的讨论,它必须是可能的.

java swing jtextpane jcomponent alignment

4
推荐指数
1
解决办法
4908
查看次数

如何确定Docker版本

当我运行时:

$ docker -v
Run Code Online (Sandbox Code Playgroud)

输出是:

Docker version 18.06.1-ce, build e68fc7a
Run Code Online (Sandbox Code Playgroud)

他们写的时候是什么版本

如果您使用 Docker 1.13 或更高版本,请改用 --cpus。

问是因为 18 和 1 之间的差异对我来说太大了。文档可以这么老吗?还是 docker 版本增长这么快?

docker

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

模拟状态在 JUnit 测试方法调用之间丢失

我不明白为什么test1()失败,尽管它与test2(). 而另一种测试方法成功了......

我得到了 NPE assertTrue(str.equals("hello"));

import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import junit.framework.TestCase;

class UnderTest {
    private static UnderTest instance;
    private ToMock toMock;

    public void doSomething() {
        String str = toMock.get();
        assertTrue(str.equals("hello"));
    }

    public static UnderTest getInstance() {
        if (instance == null) {
            instance = new UnderTest();
        }
        return instance;
    }

    public void set(ToMock toMock) {
        this.toMock = toMock;
    } …
Run Code Online (Sandbox Code Playgroud)

java testing junit mocking mockito

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

为什么我必须关闭 XSL 中的 &lt;br&gt; 标记?

我有时会做 XSLT。所以我可能有些不明白。

不确定是否需要示例,但这里是: XML 非常简单:

<a></a>
Run Code Online (Sandbox Code Playgroud)

XSL:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <xsl:apply-templates select="a"/>
  </xsl:template>
  <xsl:template match="a">
    <html>
      <head>
        <title>Title</title>
      </head>
      <body><br></body>
    </html>
  </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

Java代码:

public static String transform(String xml, String xsl) throws TransformerException {

    StreamSource xslT = new StreamSource(new StringReader(xsl));

    TransformerFactory tFactory = TransformerFactory.newInstance();

    Transformer transformer = tFactory.newTransformer(xslT);

    StreamSource source = new StreamSource(new StringReader(xml));

    StringWriter out = new StringWriter();
    StreamResult result = new StreamResult(out);

    transformer.transform(source, result);
    return out.toString();

}
Run Code Online (Sandbox Code Playgroud)

我认为如果我html在样式表中使用输出类型,那么它应该被识别<br>为有效的 …

html java tags xslt

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

logcat 无法识别 --regex 选项

根据文档https://developer.android.com/studio/command-line/logcat.html logcat 应该支持该选项:

-e <expr>, --regex=<expr>   Only print lines where the log message matches <expr> where <expr> is a regular expression.
Run Code Online (Sandbox Code Playgroud)

但是我无法使用此选项运行 logcat:

$ ./adb logcat --regex="Vocabulary"
unknown option -- -Unrecognized Option

$ ./adb logcat -e "Vocabulary"
unknown option -- eUnrecognized Option
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

regex android android-logcat

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

使用com.sun.net.httpserver.HttpServer时不调用ServletContextListener

com.sun.net.httpserver.HttpServer在集成测试中使用.它完成了它的工作,但我注意到ServletContextListener's在测试期间没有调用方法.当我将应用程序部署到真正的Tomcat服务器时,我可以看到它的方法被调用.

以下是监听器类:

package abc;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class StartupListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent event) {
        System.out.println("########################################");
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        System.out.println("########################################");
    }
}
Run Code Online (Sandbox Code Playgroud)

以下是我HttpServer在测试中的启动方式:

@BeforeClass
public static void startServer() {
    URI uri = UriBuilder.fromUri("http://localhost/").port(8080).build();

    // Create an HTTP server listening at port 8080
    try {
        server = HttpServer.create(new InetSocketAddress(uri.getPort()), 0);
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }

    // Create a handler wrapping …
Run Code Online (Sandbox Code Playgroud)

-1
推荐指数
1
解决办法
220
查看次数