我有一个(大)提交树,其中包含几个我想要重新绑定到另一个提交的合并提交.执行正常的rebase会导致git要求我解决合并冲突.我不想审查每个合并,因为这将是很多工作.在找到--preserve-merges选项后,这里有一个很好的解释,我认为我找到了完成这项任务的完美工具.但是,我似乎无法让它正常工作.我创建了一个演示问题的玩具示例.
从空文件夹开始,我们首先创建一个带有合并的分支和另一个我们将在其上进行rebase的分支.
A---B--
\ \
---C---D
\
---E
Run Code Online (Sandbox Code Playgroud)
其中主指乙,分支指d和再见分支指È.
git init
echo Hello > Hello.txt
git add Hello.txt
git commit -m "Create Hello.txt (commit A)"
git tag start
echo World! >> Hello.txt
git commit -am "Change to Hello World (commit B)"
git checkout start
git checkout -b branch
echo Dave >> Hello.txt
git commit -am "Change to Hello Dave (commit C)"
git merge master
echo Hello …
Run Code Online (Sandbox Code Playgroud) 我想压缩一些数据,所以我遇到了DeflatorInputStream和DeflatorOutputStream类.但是,以下示例显示在使用这些类时,我似乎无法重建原始数据.
当我切换到ZipInputStream和ZipOutputStream它确实有效,但由于我本身不需要zip文件,我认为通用压缩会更好.主要是我有兴趣理解为什么这个例子不起作用.
//Create some "random" data
int bytesLength = 1024;
byte[] bytes = new byte[bytesLength];
for(int i = 0; i < bytesLength; i++) {
bytes[i] = (byte) (i % 10);
}
//Compress the data, and write it to somewhere (a byte array for this example)
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
DeflaterOutputStream outputStream = new DeflaterOutputStream(arrayOutputStream);
outputStream.write(bytes);
//Read and decompress the data
byte[] readBuffer = new byte[5000];
ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(arrayOutputStream.toByteArray());
DeflaterInputStream inputStream = new DeflaterInputStream(arrayInputStream);
int read = inputStream.read(readBuffer); …
Run Code Online (Sandbox Code Playgroud) 假设我有一个类定义了要完成的大块工作,可以产生几个已检查的异常.
class WorkerClass{
public Output work(Input input) throws InvalidInputException, MiscalculationException {
...
}
}
Run Code Online (Sandbox Code Playgroud)
现在假设我有一个可以调用这个类的GUI.我使用SwingWorker委派任务.
Final Input input = getInput();
SwingWorker<Output, Void> worker = new SwingWorker<Output, Void>() {
@Override
protected Output doInBackground() throws Exception {
return new WorkerClass().work(input);
}
};
Run Code Online (Sandbox Code Playgroud)
如何处理从SwingWorker抛出的可能异常?我想区分我的worker类的异常(InvalidInputException和MiscalculationException),但ExecutionException包装器使事情变得复杂.我只想处理这些异常 - 不应该捕获OutOfMemoryError.
try{
worker.execute();
worker.get();
} catch(InterruptedException e){
//Not relevant
} catch(ExecutionException e){
try{
throw e.getCause(); //is a Throwable!
} catch(InvalidInputException e){
//error handling 1
} catch(MiscalculationException e){
//error handling 2
}
}
//Problem: Since a Throwable is thrown, …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个应用程序,在某些时候启动一个工作线程.此线程的行为将根据用于启动它的参数而有很大差异,但以下属性列表适用:
由于可能持续时间很长(5分钟到几个小时,具体取决于输入),我们希望能够中止计算.如果我们选择中止它,我们不再关心输出,并且线程实际上只要它继续运行就浪费宝贵的资源.由于代码在我们的控制之下,建议的方法是使用中断来指示中止.
虽然Web上的大多数示例都涉及循环某些方法的工作线程,但对我来说情况并非如此(此处类似的问题).在这个工作线程中也很少有阻塞调用,在这种情况下,本文建议手动检查中断标志.我的问题是:如何处理这个中断?
我看到了几个选项,但无法确定哪种选择最"干净".尽管我有实际的例子,但我主要对如何处理这个问题的"最佳实践"感兴趣.
ThreadDeath
了已弃用的Thread#stop()
方法所使用的方法及其所有相关问题.我可以看到这种方法在拥有的代码中是可接受的(由于已知的逻辑流程),但在库代码中却没有.ThreadDeath
终止线程,并通过强制程序员处理此事件来缓解类似问题.但是,它给代码带来了很大的负担,需要在任何地方提到异常.有一个原因并非一切都会抛出InterruptedException
.NullPointerExceptions
可能会出现空结果,导致与第1点相同的问题.在大型代码库中几乎不可能找到这些原因.我正在学习 AWS Lambda。我创建了一个 lambda,它将充当 REST API(APIEvent
用 CloudFormation 术语来说),并希望使用事件在本地调试该 Lambda。
如果我理解正确的话,运行sam local generate-event apigateway aws-proxy
会生成一个适合本地运行/调试我的 Lambda 的事件。这会产生以下事件(一些嵌套值被缩写):
{
"body": "eyJ0ZXN0IjoiYm9keSJ9",
"resource": "/{proxy+}",
"path": "/path/to/resource",
"httpMethod": "POST",
"isBase64Encoded": true,
"queryStringParameters": {
"foo": "bar"
},
"multiValueQueryStringParameters": {
"foo": [
"bar"
]
},
"pathParameters": {
"proxy": "/path/to/resource"
},
"stageVariables": {
"baz": "qux"
},
"headers": {
...
},
"multiValueHeaders": {
...
},
"requestContext": {
"accountId": "123456789012",
"resourceId": "123456",
"stage": "prod",
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
"requestTime": "09/Apr/2015:12:34:56 +0000",
"requestTimeEpoch": 1428582896000,
"identity": {
...
}, …
Run Code Online (Sandbox Code Playgroud) 我正在按照Maven的示例指南来学习Maven.
我正忙着完成第7章,这是一个包含spring和hibernate的简单多模块企业项目.本章的示例文件可以下载在这里,在CH-多弹簧目录.
第7.1至7.6节讨论了每个模块的细节.在第7节中,生成数据库并运行应用程序.正是在这一步,我收到以下错误:
> mvn hibernate3:hbm2ddl -X
<Some output left out>
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Multi-Spring Chapter Simple Parent Project ........ FAILURE [0.752s]
[INFO] Multi-Spring Chapter Simple Object Model .......... SKIPPED
[INFO] Multi-Spring Chapter Simple Weather API ........... SKIPPED
[INFO] Multi-Spring Chapter Simple Persistence API ....... SKIPPED
[INFO] Multi-Spring Chapter Simple Command Line Tool ..... SKIPPED
[INFO] Multi-Spring Chapter Simple Web Application ....... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE …
Run Code Online (Sandbox Code Playgroud) java ×3
aws-lambda ×1
aws-sam ×1
compression ×1
deflate ×1
git ×1
git-rebase ×1
hbm2ddl ×1
interrupt ×1
maven ×1
swingworker ×1