Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/ChangelogEntryBuilder.java @ 622:4e6179bde4fc
Update to comply with Java 1.5 target
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 20 May 2013 16:56:40 +0200 |
parents | 7c0d2ce340b8 |
children | fba85bc1dfb8 |
comparison
equal
deleted
inserted
replaced
621:99ad1e3a4e4d | 622:4e6179bde4fc |
---|---|
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
18 | 18 |
19 import java.io.ByteArrayOutputStream; | 19 import java.io.ByteArrayOutputStream; |
20 import java.io.UnsupportedEncodingException; | |
20 import java.util.ArrayList; | 21 import java.util.ArrayList; |
21 import java.util.Collection; | 22 import java.util.Collection; |
22 import java.util.Collections; | 23 import java.util.Collections; |
23 import java.util.Iterator; | 24 import java.util.Iterator; |
24 import java.util.LinkedHashMap; | 25 import java.util.LinkedHashMap; |
28 import java.util.TimeZone; | 29 import java.util.TimeZone; |
29 | 30 |
30 import org.tmatesoft.hg.core.HgIOException; | 31 import org.tmatesoft.hg.core.HgIOException; |
31 import org.tmatesoft.hg.core.Nodeid; | 32 import org.tmatesoft.hg.core.Nodeid; |
32 import org.tmatesoft.hg.internal.DataSerializer.DataSource; | 33 import org.tmatesoft.hg.internal.DataSerializer.DataSource; |
34 import org.tmatesoft.hg.repo.HgInvalidStateException; | |
33 import org.tmatesoft.hg.util.Path; | 35 import org.tmatesoft.hg.util.Path; |
34 | 36 |
35 /** | 37 /** |
36 * Builds changelog entry | 38 * Builds changelog entry |
37 * @author Artem Tikhomirov | 39 * @author Artem Tikhomirov |
112 public int serializeLength() { | 114 public int serializeLength() { |
113 return -1; | 115 return -1; |
114 } | 116 } |
115 | 117 |
116 public byte[] build() { | 118 public byte[] build() { |
117 ByteArrayOutputStream out = new ByteArrayOutputStream(); | 119 try { |
118 final int LF = '\n'; | 120 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
119 CharSequence extras = buildExtras(); | 121 final int LF = '\n'; |
120 CharSequence files = buildFiles(); | 122 CharSequence extras = buildExtras(); |
121 byte[] manifestRevision = manifestRev.toString().getBytes(); | 123 CharSequence files = buildFiles(); |
122 byte[] username = user().getBytes(EncodingHelper.getUTF8()); | 124 byte[] manifestRevision = manifestRev.toString().getBytes(); |
123 out.write(manifestRevision, 0, manifestRevision.length); | 125 byte[] username = user().getBytes(EncodingHelper.getUTF8().name()); // XXX Java 1.5 |
124 out.write(LF); | 126 out.write(manifestRevision, 0, manifestRevision.length); |
125 out.write(username, 0, username.length); | 127 out.write(LF); |
126 out.write(LF); | 128 out.write(username, 0, username.length); |
127 final long csetDate = csetTime(); | 129 out.write(LF); |
128 byte[] date = String.format("%d %d", csetDate, csetTimezone(csetDate)).getBytes(); | 130 final long csetDate = csetTime(); |
129 out.write(date, 0, date.length); | 131 byte[] date = String.format("%d %d", csetDate, csetTimezone(csetDate)).getBytes(); |
130 if (extras.length() > 0) { | 132 out.write(date, 0, date.length); |
131 out.write(' '); | 133 if (extras.length() > 0) { |
132 byte[] b = extras.toString().getBytes(); | 134 out.write(' '); |
135 byte[] b = extras.toString().getBytes(); | |
136 out.write(b, 0, b.length); | |
137 } | |
138 out.write(LF); | |
139 byte[] b = files.toString().getBytes(); | |
133 out.write(b, 0, b.length); | 140 out.write(b, 0, b.length); |
141 out.write(LF); | |
142 out.write(LF); | |
143 byte[] cmt = comment.toString().getBytes(EncodingHelper.getUTF8().name()); // XXX Java 1.5 | |
144 out.write(cmt, 0, cmt.length); | |
145 return out.toByteArray(); | |
146 } catch (UnsupportedEncodingException ex) { | |
147 throw new HgInvalidStateException(ex.getMessage()); // Can't happen, UTF8 is always there | |
134 } | 148 } |
135 out.write(LF); | |
136 byte[] b = files.toString().getBytes(); | |
137 out.write(b, 0, b.length); | |
138 out.write(LF); | |
139 out.write(LF); | |
140 byte[] cmt = comment.toString().getBytes(EncodingHelper.getUTF8()); | |
141 out.write(cmt, 0, cmt.length); | |
142 return out.toByteArray(); | |
143 } | 149 } |
144 | 150 |
145 private CharSequence buildExtras() { | 151 private CharSequence buildExtras() { |
146 StringBuilder extras = new StringBuilder(); | 152 StringBuilder extras = new StringBuilder(); |
147 for (Iterator<Entry<String, String>> it = extrasMap.entrySet().iterator(); it.hasNext();) { | 153 for (Iterator<Entry<String, String>> it = extrasMap.entrySet().iterator(); it.hasNext();) { |