为了显示可重现的场景,我正在做以下事情
获取当前系统时间(当地时间)
将本地时间转换为UTC //在这里工作正常
反转UTC时间,返回当地时间.遵循3种不同的方法(如下所列),但所有3种方法仅保留UTC时间.
{
long ts = System.currentTimeMillis();
Date localTime = new Date(ts);
String format = "yyyy/MM/dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat (format);
// Convert Local Time to UTC (Works Fine)
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date gmtTime = new Date(sdf.format(localTime));
System.out.println("Local:" + localTime.toString() + "," + localTime.getTime() + " --> UTC time:" + gmtTime.toString() + "-" + gmtTime.getTime());
// Reverse Convert UTC Time to Locale time (Doesn't work) Approach 1
sdf.setTimeZone(TimeZone.getDefault());
localTime = new Date(sdf.format(gmtTime));
System.out.println("Local:" + localTime.toString() + "," …Run Code Online (Sandbox Code Playgroud)java utc simpledateformat date-formatting timestamp-with-timezone
我需要从大文件中读取最后n行(比如2GB).该文件是UTF-8编码的.
想知道最有效的方法.在java中读取RandomAccessFile,但是seek()方法读取内存中的整个文件.它使用本机实现,因此我无法引用源代码.
我有我的自定义Java对象,并希望利用内置序列化中的JVM将其发送到Kafka主题,但序列化失败,出现以下错误
org.apache.kafka.common.errors.SerializationException:无法将类com.spring.kafka.Payload的值转换为value.serializer中指定的类org.apache.kafka.common.serialization.ByteArraySerializer
Payload.java
public class Payload implements Serializable {
private static final long serialVersionUID = 123L;
private String name="vinod";
private int anInt = 5;
private Double aDouble = new Double("5.0");
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAnInt() {
return anInt;
}
public void setAnInt(int anInt) {
this.anInt = anInt;
}
public Double getaDouble() {
return aDouble;
}
public void setaDouble(Double aDouble) {
this.aDouble = aDouble;
}
}
Run Code Online (Sandbox Code Playgroud)
在我创建生产者期间,我设置了以下属性 …
在给定的json文档中,如何验证json路径是否存在?
我正在使用jayway-jsonpath并拥有以下代码
JsonPath.read(jsonDocument, jsonPath)
Run Code Online (Sandbox Code Playgroud)
上面的代码可能会抛出异常
com.jayway.jsonpath.PathNotFoundException:路径没有结果:$ ['abc']
为了减轻它,我打算在尝试使用JsonPath.read读取它之前验证路径是否存在
作为参考,我经历了以下两个文档,但无法真正得到我想要的.
我是 Apache ActiveMQ 的新手。从 Producer 我发送以下内容:
{"senderPhNumber":"9986085716","sendingTime":"2015-07-20T22:11:24","spCode":"000001","customerName":"Vinod"}
Run Code Online (Sandbox Code Playgroud)
来自生产者的代码
String text = messageStr;
TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
System.out.println("Sent message: " + text );
producer.send(message);
Run Code Online (Sandbox Code Playgroud)
来自 Consumer 的消息类型为ActiveMqMessage。消费者实现MessageListener和内部onMessage()我有以下代码:
public void onMessage(Message msg) {
if (msg instanceof ActiveMQMessage){
System.out.println("Inside If");
try {
ActiveMQMessage aMsg = (ActiveMQMessage)msg;
System.out.println( " Inside Listener ..." + aMsg);
ProducerInfo prod = (ProducerInfo) aMsg.getDataStructure();
consumer.close();
session.close();
connection.close();
} catch (JMSException e) {
e.printStackTrace();
}
} …Run Code Online (Sandbox Code Playgroud) 在我的用户输入字段中,我想允许某些特殊字符、字母和数字的组合。我应该确保从任何语言键入时正则表达式模式都允许此设置。基本上我构建的这个正则表达式也应该支持 unicode 表示。如何使用 Java 中的 Pattern 类来实现这一点?
\n\n这里给出了我尝试过的示例代码。但这不包括除英语之外的任何其他语言的字母/数字。
\n\nprivate static final String ADDRESS_LINE_PATTERN = "[A-Za-z0-9,\\\\s#\\\\-.]+";\n\n\n public static boolean isInputValid(String patternToValidate, String input){\n Pattern p = Pattern.compile(patternToValidate);\n Matcher m = p.matcher(input);\n boolean b = m.matches();\n return b;\n\n }\n\npublic static void main(){\nString value = "\xe3\x82\xb3\xe3\x83\xad\xe3\x83\xb3";\nSystem.out.println("Value:" + value + " - valid? " + isInputValid(ADDRESS_LINE_PATTERN, value));\n}\nRun Code Online (Sandbox Code Playgroud)\n 我注意到以下来自datastax cassandra java驱动程序的WARN日志消息。请帮助理解此消息。它有多关键?有什么影响?如何解决。
Cassandra版本:2.1.8
Datastax Java驱动程序:3.1.0
WARN 2017-02-23 14:54:53,926 com.datastax.driver.core.Cluster:localhost-startStop-1-您在联系点中列出了nosql.campany.com/192.168.89.184:9042,但并非如此在控制主机的系统中找到
我是 GitHub Actions 的新手。我有以下 DockerFile
FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 GitHub Action Publish Docker,下面是我的操作代码
name: Publish Docker
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
name: myDocker/repository
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
Run Code Online (Sandbox Code Playgroud)
构建失败并出现以下错误
Step 5/6 : COPY ${JAR_FILE} app.jar
COPY failed: no source files were specified
Run Code Online (Sandbox Code Playgroud)
我假设它无法在目标文件夹下获取 jar 文件。我是否应该在 …
我在 AWS Lightsail 上构建了一个 WordPress 网站,需要将其转移到另一个 AWS 账户。
推荐的方法是什么?
我正在考虑以下方法
没有办法直接跨帐户共享 Lightsail 快照吗?
我已经看到了许多与此错误相关的答案,但是所有答案都重定向到了scala版本等。但是我认为我的情况有所不同。
我有一个使用2.10版设置的远程Spark主工作者集群。我能够通过列出所有工作程序节点的http:// master-ip:8080进行验证
在我的应用程序中,我尝试使用Java 7代码创建SparkConf。以下是代码
sparkConf = new SparkConf(true)
.set("spark.cassandra.connection.host", "localhost")
.set("spark.cassandra.auth.username", "username")
.set("spark.cassandra.auth.password", "pwd")
.set("spark.master", "spark://master-ip:7077")
.set("spark.app.name","Test App");
Run Code Online (Sandbox Code Playgroud)
以下是我添加的Maven依赖项
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector_2.10</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.1.0</version>
<exclusions>
<exclusion>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
Caused by: java.lang.NoSuchMethodError: scala.Predef$.$conforms()Lscala/Predef$$less$colon$less;
at org.apache.spark.util.Utils$.getSystemProperties(Utils.scala:1710)
at org.apache.spark.SparkConf.loadFromSystemProperties(SparkConf.scala:73)
at org.apache.spark.SparkConf.<init>(SparkConf.scala:68)
Run Code Online (Sandbox Code Playgroud)
来自工作节点之一的Spark版本
./spark-shell --version
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 2.1.0
/_/
Using Scala version 2.11.8, Java …Run Code Online (Sandbox Code Playgroud)