Skip to content

Commit

Permalink
refactor exsting code
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenSammi committed Nov 12, 2024
1 parent 1afacb0 commit 0fcd744
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,7 @@ public OzoneTokenIdentifier fromUniqueSerializedKey(byte[] rawData)
return this;
}

/**
* Overrides default implementation to write using Protobuf.
*
* @param out output stream
* @throws IOException
*/
@Override
public void write(DataOutput out) throws IOException {
public OMTokenProto toProtoBuf() throws IOException {
OMTokenProto.Builder builder = OMTokenProto.newBuilder()
.setMaxDate(getMaxDate())
.setType(getTokenType())
Expand All @@ -182,9 +175,18 @@ public void write(DataOutput out) throws IOException {
builder.setOmServiceId(getOmServiceId());
}
}
return builder.build();
}

OMTokenProto token = builder.build();
out.write(token.toByteArray());
/**
* Overrides default implementation to write using Protobuf.
*
* @param out output stream
* @throws IOException
*/
@Override
public void write(DataOutput out) throws IOException {
out.write(toProtoBuf().toByteArray());
}

/**
Expand Down Expand Up @@ -320,7 +322,7 @@ public static class TokenInfo {
private byte[] password;
private String trackingId;

public TokenInfo(long renewDate, byte[] password) {
public TokenInfo(long renewDate, byte[] password) {
this(renewDate, password, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ message OMTokenProto {
optional string accessKeyId = 12;
optional string signature = 13;
optional string strToSign = 14;
optional string omServiceId = 15;
optional string omServiceId = 15 [deprecated = true];
optional string secretKeyId = 16;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public Class<OzoneTokenIdentifier> getTypeClass() {
}

@Override
public byte[] toPersistedFormat(OzoneTokenIdentifier object) {
public byte[] toPersistedFormat(OzoneTokenIdentifier object) throws IOException{
Preconditions
.checkNotNull(object, "Null object can't be converted to byte array.");
return object.toUniqueSerializedKey();
return object.toProtoBuf().toByteArray();
}

@Override
Expand All @@ -60,11 +60,11 @@ public OzoneTokenIdentifier fromPersistedFormat(byte[] rawData)
Preconditions.checkNotNull(rawData,
"Null byte array can't converted to real object.");
try {
OzoneTokenIdentifier object = OzoneTokenIdentifier.newInstance();
return object.fromUniqueSerializedKey(rawData);
return OzoneTokenIdentifier.readProtoBuf(rawData);
} catch (IOException ex) {
try {
return OzoneTokenIdentifier.readProtoBuf(rawData);
OzoneTokenIdentifier object = OzoneTokenIdentifier.newInstance();
return object.fromUniqueSerializedKey(rawData);
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException(
"Can't encode the the raw data from the byte array", e);
Expand Down

0 comments on commit 0fcd744

Please sign in to comment.