mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
mv com/google/domain/registry google/registry
This change renames directories in preparation for the great package rename. The repository is now in a broken state because the code itself hasn't been updated. However this should ensure that git correctly preserves history for each file.
This commit is contained in:
parent
a41677aea1
commit
5012893c1d
2396 changed files with 0 additions and 0 deletions
70
java/google/registry/rde/RydeTarOutputStream.java
Normal file
70
java/google/registry/rde/RydeTarOutputStream.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.domain.registry.rde;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.auto.factory.AutoFactory;
|
||||
import com.google.domain.registry.util.ImprovedOutputStream;
|
||||
import com.google.domain.registry.util.PosixTarHeader;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.annotation.WillNotClose;
|
||||
|
||||
/**
|
||||
* Single-file POSIX tar archive creator that wraps an {@link OutputStream}.
|
||||
*/
|
||||
@AutoFactory(allowSubclasses = true)
|
||||
public class RydeTarOutputStream extends ImprovedOutputStream {
|
||||
|
||||
/**
|
||||
* Creates a new instance that outputs a tar archive.
|
||||
*
|
||||
* @param os is the upstream {@link OutputStream} which is not closed by this object
|
||||
* @param size is the length in bytes of the one file, which you will write to this object
|
||||
* @param modified is the {@link PosixTarHeader.Builder#setMtime mtime} you want to set
|
||||
* @param filename is the name of the one file that will be contained in this archive
|
||||
* @throws RuntimeException to rethrow {@link IOException}
|
||||
* @throws IllegalArgumentException if {@code size} is negative
|
||||
*/
|
||||
public RydeTarOutputStream(
|
||||
@WillNotClose OutputStream os, long size, DateTime modified, String filename) {
|
||||
super(os, false, size);
|
||||
checkArgument(size >= 0);
|
||||
checkArgument(filename.endsWith(".xml"),
|
||||
"Ryde expects tar archive to contain a filename with an '.xml' extension.");
|
||||
try {
|
||||
os.write(new PosixTarHeader.Builder()
|
||||
.setName(filename)
|
||||
.setSize(size)
|
||||
.setMtime(modified)
|
||||
.build()
|
||||
.getBytes());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Writes the end of archive marker. */
|
||||
@Override
|
||||
public void onClose() throws IOException {
|
||||
// Round up to a 512-byte boundary and another 1024-bytes to indicate end of archive.
|
||||
write(new byte[1024 + 512 - (int) (getBytesWritten() % 512L)]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue