private void paxHeaders() throws IOException { BufferedInputStream br = new BufferedInputStream(this); Map headers = new HashMap(); // Format is "length keyword=value\n"; while (true) { // get length int ch; int len = 0; int read = 0; while ((ch = br.read()) != -1) { read++; if (ch == ' ') { // End of length string // Get keyword StringBuffer sb = new StringBuffer(); while ((ch = br.read()) != -1) { read++; if (ch == '=') { // end of keyword String keyword = sb.toString(); // Get rest of entry byte[] cbuf = new byte[len - read]; int got = br.read(cbuf); if (got != len - read) { throw new IOException( "Failed to read Paxheader. Expected " + (len - read) + " chars, read " + got); } String value = new String(cbuf, 0, len - read - 1); // Drop trailing NL headers.put(keyword, value); break; } sb.append((char) ch); } break; // Processed single header } len *= 10; len += ch - '0'; } if (ch == -1) { // EOF break; } } getNextEntry(); // Get the actual file entry /* * The following headers are defined for Pax. * atime, ctime, mtime, charset: cannot use these without changing TarArchiveEntry fields * comment * gid, gname * linkpath * size * uid,uname */ Iterator hdrs = headers.entrySet().iterator(); while (hdrs.hasNext()) { Entry ent = (Entry) hdrs.next(); String key = (String) ent.getKey(); String val = (String) ent.getValue(); if ("path".equals(key)) { currEntry.setName(val); } else if ("linkpath".equals(key)) { currEntry.setLinkName(val); } else if ("gid".equals(key)) { currEntry.setGroupId(Integer.parseInt(val)); } else if ("gname".equals(key)) { currEntry.setGroupName(val); } else if ("uid".equals(key)) { currEntry.setUserId(Integer.parseInt(val)); } else if ("uname".equals(key)) { currEntry.setUserName(val); } else if ("size".equals(key)) { currEntry.setSize(Long.parseLong(val)); } } }
private void paxHeaders() throws IOException { Reader br = new InputStreamReader(this, "UTF-8") { @Override public void close() { // make sure GC doesn't close "this" before we are done } }; Map<String, String> headers = new HashMap<String, String>(); // Format is "length keyword=value\n"; try { while (true) { // get length int ch; int len = 0; int read = 0; while ((ch = br.read()) != -1) { read++; if (ch == ' ') { // End of length string // Get keyword StringBuffer sb = new StringBuffer(); while ((ch = br.read()) != -1) { read++; if (ch == '=') { // end of keyword String keyword = sb.toString(); // Get rest of entry char[] cbuf = new char[len - read]; int got = br.read(cbuf); if (got != len - read) { throw new IOException( "Failed to read " + "Paxheader. Expected " + (len - read) + " chars, read " + got); } // Drop trailing NL String value = new String(cbuf, 0, len - read - 1); headers.put(keyword, value); break; } sb.append((char) ch); } break; // Processed single header } len *= 10; len += ch - '0'; } if (ch == -1) { // EOF break; } } } finally { // NO-OP but makes FindBugs happy br.close(); } getNextEntry(); // Get the actual file entry /* * The following headers are defined for Pax. * atime, ctime, mtime, charset: cannot use these without changing TarArchiveEntry fields * comment * gid, gname * linkpath * size * uid,uname */ for (Entry<String, String> ent : headers.entrySet()) { String key = ent.getKey(); String val = ent.getValue(); if ("path".equals(key)) { currEntry.setName(val); } else if ("linkpath".equals(key)) { currEntry.setLinkName(val); } else if ("gid".equals(key)) { currEntry.setGroupId(Integer.parseInt(val)); } else if ("gname".equals(key)) { currEntry.setGroupName(val); } else if ("uid".equals(key)) { currEntry.setUserId(Integer.parseInt(val)); } else if ("uname".equals(key)) { currEntry.setUserName(val); } else if ("size".equals(key)) { currEntry.setSize(Long.parseLong(val)); } } }