我有以下字符串:String timeStamp = "2020-01-31 12:13:14 +03:00"。我尝试使用 Java 8 DateTimeFormatter 解析它。
DateTimeFormatter formatter = DateTimeFormatter.ofPattern( format );
tmpTimestamp = ZonedDateTime.parse( timeStamp, formatter );
Run Code Online (Sandbox Code Playgroud)
其中format之一是:
"yyyy-MM-dd' 'HH:mm:ss' 'Z",
"yyyy-MM-dd' 'HH:mm:ss' 'X",
"yyyy-MM-dd' 'HH:mm:ss' 'x",
"yyyy-MM-dd HH:mm:ss Z",
"yyyy-MM-dd HH:mm:ss X",
"yyyy-MM-dd HH:mm:ss x",
Run Code Online (Sandbox Code Playgroud)
没有一个在工作。我总是DateTimeParseException在偏移子字符串“+03:00”中指向“+”或“:”字符
根据 JavaDocs:类 DateTimeFormatter "+03:00" 应受以下任一支持:Z、X和x。
那么问题是如何构造格式化字符串来解析它呢?
在阅读RTMP规范后,为了编写一个基本的RTMP服务器,我无法确定是否可以通过同一块流(块流ID)发送多个消息(消息流ID)。
第5.3.2节分享了两个示例:一个示例,其中具有相同流ID的多个消息通过多个块依次发送给单个块流ID,另一个示例是通过多个块按单个块流ID发送单个消息。
但是,没有示例说明针对单个块流ID在多个块上同时发送具有不同流ID的多条消息。我找不到能阻止这种情况的任何东西,但我想确认一下。
例如,假设您有两条消息,如示例2所示
+-----------+-------------------+-----------------+-----------------+
| | Message Stream ID | Message TYpe ID | Time | Length |
+-----------+-------------------+-----------------+-----------------+
| Msg # 1 | 27 | 9 (video) | 1000 | 307 |
+-----------+-------------------+-----------------+-----------------+
| Msg # 2 | 42 | 9 (video) | 1000 | 197 |
+-----------+-------------------+-----------------+-----------------+
Run Code Online (Sandbox Code Playgroud)
RTMP客户端可以发送以下块顺序吗?
换句话说,是否希望块3使用1或2中的标头(即基于消息流ID)?
我正在写一个小网站,每个页面,我都在其标题中添加一个服务器名称:
func httpSignUp(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Server", SERVER_NAME)
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种方法可以设置http.ResponseWriter的默认服务器名称,所以我不必一遍又一遍地使用相同的行?
我在Java中有这个代码片段:
List<Integer> li= Arrays.asList(1, 2, 3, null, 4, 5, null, 6, 7, 8);
li.stream().filter(e-> e!=null)
.map(e-> {System.out.print(" m "+ e); return e * 2;})
.filter(e-> e % 3 == 0)
.forEach(e-> {System.out.println(" fe " + e);});
Run Code Online (Sandbox Code Playgroud)
输出是
m 1 m 2 m 3 fe 6
m 4 m 5 m 6 fe 12
m 7 m 8
Run Code Online (Sandbox Code Playgroud)
我知道filter,map是中间方法,这意味着它们只有在调用像forEach这样的终端方法时才会开始工作.但我不能只围绕它们被调用的确切顺序,并在这种情况下开始工作.有人可以向我解释这个输出是怎么来的吗?
你能解释为什么第一个lambda正在捕获而第二个没有捕获.
Runnable createLambdaWithCapture() {
return System.out::println;
}
Runnable createLambdaWithApparentCapture() {
return () -> System.out.println();
}
Run Code Online (Sandbox Code Playgroud) 我正在测试用 Java 和 Spring Boot 编写的应用程序,我有一个问题。我的测试模拟一个 HTTP 请求,该请求仅当customData数据放置在Cookie标头内时才有效。这是我的简单测试的代码:
@Test
public void myFristTest() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post(MY_URL)
.header("Cookie", "customData=customString")
.accept(MediaType.APPLICATION_JSON_VALUE)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(ConversionUtil.objectToString(BODY_OF_MY_REQUEST)))
.andExpect(status().isCreated());
}
Run Code Online (Sandbox Code Playgroud)
不幸的是这个测试失败了。用于测试的Java代码如下:
String customData;
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("customData")) {
customData = cookie.getValue();
}
}
}
if(customData != null) {
// code that returns HTTP status isCreated
} else {
throw new HttpServerErrorException(HttpStatus.FOUND, "Error 302");
}
Run Code Online (Sandbox Code Playgroud)
在实践中,似乎没有找到customData应该从请求标头中获取的字符串!Cookie …
public int getColsBy(final Collection<Room> rooms) {
return rooms.stream()
.max((lhs, rhs) -> lhs.right - rhs.right).get().right;
}
Run Code Online (Sandbox Code Playgroud)
我尝试在我的libgdx项目中执行此代码,但是我所拥有的只是例外!
04-15 22:34:21.136 32610-32636/com.mygdx.game E/AndroidRuntime: FATAL EXCEPTION: GLThread 8116
Process: com.mygdx.game, PID: 32610
java.lang.NoSuchMethodError: No interface method stream()Ljava/util/stream/Stream; in class Ljava/util/Collection; or its super classes (declaration of 'java.util.Collection' appears in /system/framework/core-libart.jar)
at com.mygdx.game.enviroment.LevelParser.getColsBy(LevelParser.java:44)
at com.mygdx.game.enviroment.LevelParser.parseFrom(LevelParser.java:30)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:38)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1550)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)
Run Code Online (Sandbox Code Playgroud)
有我的build.gradle文件
buildscript {
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:2.1.0-beta1'
classpath 'org.robovm:robovm-gradle-plugin:1.12.0'
classpath …Run Code Online (Sandbox Code Playgroud) 我有一个程序,java.net.http.HttpClient它利用 Java 11 中引入的 来连接内部服务并向内部服务发送请求。这些服务相互验证,均提供内部 CA 颁发的证书。
例如,
SSLContext sslContext = SSLContext.getInstance("TLSv1.3");
KeyManager keys = /* load our cert and key */;
TrustManager trust = /* load our trusted CA */;
sslContext.init(keys, trust, secureRandom);
HttpClient.Builder builder = HttpClient.newBuilder().sslContext(sslContext);
HttpClient client = builder.build();
Run Code Online (Sandbox Code Playgroud)
在我们的主机上,客户端的证书和私钥会定期轮换,比主机或应用程序有机会重新启动的频率更高。我希望能够在新的证书/密钥对仍在运行时重新加载它,但看不到任何方法可以做到这一点HttpClient。SSLContext
构建完成后HttpClient,它仅提供一个sslContext()getter 来检索SSLContext. 似乎没有 API 来设置新的。
还有其他机制可以实现这一目标吗?
(我正在考虑类似于 Jetty 的SslContextFactory#reload(SSLContext)方法。)
这是我第一次使用 spring,我有点卡住了。这是我到目前为止所拥有的
我在嵌入式 tomcat 上运行的应用程序
package com.company.project.application;
@SpringBootApplication
public class SampleApplication {
private static Log logger = LogFactory.getLog(SampleApplication.class);
@Bean
protected ServletContextListener listener(){
return new ServletContextListener() {
public void contextInitialized(ServletContextEvent servletContextEvent) {
logger.info("ServletContext initialized ...");
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
logger.info("ServletContext destroyed ... ");
}
};
}
public static void main (String[] args){
SpringApplication.run(SampleApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器
package com.company.project.controller;
@Controller
public class PaymentController {
@RequestMapping("/")
@ResponseBody
public String helloWorld(){
return "hello";
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用SampleApplicaiton.main. 我可以在控制台中看到日志等。当我尝试访问http://localhost:8080/它时,它给了我 …
我正在尝试使用一些更大的整数值,但我在初始化BigInteger变量时遇到了一些问题.我一直在做:
BigInteger x = new BigInteger("" + (Math.pow(2, n)));
Run Code Online (Sandbox Code Playgroud)
其中n是100s中的某个数字,但这会引发NumberFormatException.我不认为我可以使用BigInteger,Valueof(),因为这需要很长时间,我认为不够大.任何帮助,将不胜感激.
我正在尝试将 Optional.OfNullable 方法中的集合转换为字符串,例如:
test.setAbc(Optional.ofNullable(rule.getSampleSet().toString()).orElse(null));
Run Code Online (Sandbox Code Playgroud)
但如果sampleSet是null它会给我一个NullPointerException. 谁能告诉我如何使用.map方法解决这个问题Optional?
我知道一种通过事先检查可空性来做到这一点的传统方法:
if(rule.getSampeSet != null)
Run Code Online (Sandbox Code Playgroud)
但我很想知道我们是否可以在一行中完成。